Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class model{
- private $conn;
- private $tabnm = "admin";
- public $user;
- public $userid;
- public $passid;
- public function __construct($db){
- $this->conn = $db;
- }
- function login(){
- $user = $this->cek();
- if ($user) {
- $this->user = $user;
- session_start();
- $_SESSION['nama_user'] = $user['nama_user'];
- return $user['nama_user'];
- }
- return false;
- }
- function cek(){
- $stmt = $this->conn->prepare('SELECT * FROM '.$this->tabnm.' WHERE username=? and password=?');
- $stmt->bindParam(1, $this->userid);
- $stmt->bindParam(2, $this->passid);
- $stmt->execute();
- if ($stmt->rowCount() > 0) {
- $data = $stmt->fetch(PDO::FETCH_ASSOC);
- $submitted_pass = $this->passid;
- if ($submitted_pass == $data['password']) {
- return $data;
- }
- }
- return false;
- }
- function getUser(){
- return $this->user;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment