Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Login_model {
- private $db_table = 'users';
- private $db;
- public function __construct()
- {
- $this->db = new Database;
- }
- public function checkLogin($data)
- {
- $username = htmlspecialchars($data['username']);
- $password = htmlspecialchars($data['password']);
- $query = "SELECT * FROM {$this->db_table} WHERE username = :username";
- $this->db->query($query);
- $this->db->bind('username', $username);
- $row = $this->db->result();
- if (!empty($row)) {
- if (password_verify($password, $row['password'])) {
- $_SESSION['login'] = true;
- if (isset($data['remember'])) {
- setcookie('id', '12345', strtotime("+30 days"));
- var_dump($_COOKIE['id']); die;
- }
- header("Location: ". BASEURL ."/mahasiswa");
- exit;
- } else {
- Flasher::setFlash('password anda', 'salah', 'danger');
- header('Location: '. BASEURL .'/login');
- exit;
- }
- } else {
- Flasher::setFlash('username anda', 'salah', 'danger');
- header('Location: '. BASEURL .'/login');
- exit;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement