Advertisement
irfanamir

db_connect.php

Dec 14th, 2020
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. <?php
  2. class database{
  3. var $host = "localhost";
  4. var $username = "root";
  5. var $password = "";
  6. var $database = ""; //tambahkan nilai database_user
  7. var $koneksi;
  8.  
  9. function __construct(){
  10. $this->koneksi = mysql_connect($this->host, $this->username, $this->password,$this->database)
  11. }//penggunaan mysqli
  12. //tambahkan titik koma di akhir
  13.  
  14.  
  15. function register($username,$password,$nama)
  16. {
  17. $insert = mysqli_query($this->koneksi,"insert into tb_user values ('','$username','$password','$nama')");
  18. return $insert;
  19. }
  20.  
  21. function login($username,$password,$remember)
  22. {
  23. $query = mysqli_query($this->koneksi,"select * from tb_user where username='$username'");
  24. $data_user = $query->fetch_array();
  25. if(password_verify($password,$data_user['password']))
  26. {
  27.  
  28. if($remember)
  29. {
  30. setcookie('username', $username, time() + (60 * 60 * 24 * 5), '/'); //tidak harus set time
  31. setcookie('nama', $data_user['nama'], time() + (60 * 60 * 24 * 5), '/');
  32. }
  33. $_SESSION['username'] = $username;
  34. $_SESSION['nama'] = $data_user['nama'];
  35. $_SESSION['is_login'] = TRUE;
  36. return TRUE;
  37. }
  38. }
  39.  
  40. function relogin($username)
  41. {
  42. $query = mysqli_query($this->koneksi,"select * from tb_user where username='$username'");
  43. $data_user = $query->fetch_array();
  44. $_SESSION['username'] = $username;
  45. $_SESSION['nama'] = $data_user['nama'];
  46. $_SESSION['is_login'] = TRUE;
  47. }
  48. }
  49.  
  50.  
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement