ASWADI

model

Mar 13th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <?php
  2. class model{
  3.  
  4.     private $conn;
  5.     private $tabnm = "admin";
  6.  
  7.     public $user;
  8.     public $userid;
  9.     public $passid;
  10.  
  11.     public function __construct($db){
  12.         $this->conn = $db;
  13.     }
  14.  
  15.     function login(){
  16.             $user = $this->cek();
  17.             if ($user) {
  18.                 $this->user = $user;
  19.             session_start();
  20.                 $_SESSION['nama_user'] = $user['nama_user'];
  21.                 return $user['nama_user'];
  22.             }
  23.             return false;
  24.     }
  25.  
  26.     function cek(){
  27.             $stmt = $this->conn->prepare('SELECT * FROM '.$this->tabnm.' WHERE username=? and password=?');
  28.         $stmt->bindParam(1, $this->userid);
  29.         $stmt->bindParam(2, $this->passid);
  30.             $stmt->execute();
  31.             if ($stmt->rowCount() > 0) {
  32.                 $data = $stmt->fetch(PDO::FETCH_ASSOC);
  33.                 $submitted_pass = $this->passid;
  34.                 if ($submitted_pass == $data['password']) {
  35.                     return $data;
  36.                 }
  37.             }
  38.             return false;
  39.     }
  40.  
  41.     function getUser(){
  42.             return $this->user;
  43.     }
  44.  
  45. }
  46. ?>
Add Comment
Please, Sign In to add comment