Advertisement
kangjaz

config

Sep 9th, 2017
1,246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?php
  2.  
  3. class Auth
  4. {
  5.  
  6.    public $con;
  7.  
  8.    function __construct()
  9.    {
  10.       $host = 'localhost';
  11.       $user = 'root';
  12.       $pass = '';
  13.       $db   = 'logout';
  14.  
  15.       $this->con  = new mysqli($host, $user, $pass, $db) or die($con->error);
  16.    }
  17.  
  18.    public function login($user = null, $pass = null) {
  19.  
  20.       $query = $this->con->prepare("SELECT * FROM `t_user` WHERE `username` = ? && `password` = MD5(?)");
  21.       $query->bind_param('ss', $user, $pass);
  22.       $query->execute();
  23.       $query->store_result();
  24.       $total = $query->num_rows();
  25.       $query->bind_result($id, $user, $fullname,$password);
  26.       $query->fetch();
  27.  
  28.       if ($total > 0)
  29.       {
  30.          //set_session
  31.          $_SESSION['iduser']   = $id;
  32.          $_SESSION['is_login'] = TRUE;
  33.  
  34.       } else {
  35.          echo '<script type="text/javascript">alert("Akun tidak dikenali")</script>';
  36.       }
  37.    }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement