Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class database{
- var $host = "localhost";
- var $username = "root";
- var $password = "";
- var $database = ""; //tambahkan nilai database_user
- var $koneksi;
- function __construct(){
- $this->koneksi = mysql_connect($this->host, $this->username, $this->password,$this->database)
- }//penggunaan mysqli
- //tambahkan titik koma di akhir
- function register($username,$password,$nama)
- {
- $insert = mysqli_query($this->koneksi,"insert into tb_user values ('','$username','$password','$nama')");
- return $insert;
- }
- function login($username,$password,$remember)
- {
- $query = mysqli_query($this->koneksi,"select * from tb_user where username='$username'");
- $data_user = $query->fetch_array();
- if(password_verify($password,$data_user['password']))
- {
- if($remember)
- {
- setcookie('username', $username, time() + (60 * 60 * 24 * 5), '/'); //tidak harus set time
- setcookie('nama', $data_user['nama'], time() + (60 * 60 * 24 * 5), '/');
- }
- $_SESSION['username'] = $username;
- $_SESSION['nama'] = $data_user['nama'];
- $_SESSION['is_login'] = TRUE;
- return TRUE;
- }
- }
- function relogin($username)
- {
- $query = mysqli_query($this->koneksi,"select * from tb_user where username='$username'");
- $data_user = $query->fetch_array();
- $_SESSION['username'] = $username;
- $_SESSION['nama'] = $data_user['nama'];
- $_SESSION['is_login'] = TRUE;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement