Guest User

Untitled

a guest
Jan 15th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <?php require_once("../includes/init.php");
  2. include("admin_header.php");
  3.  
  4. $login_handler = "";
  5. if (isset($_POST['submit'])) { // Form is submitted.
  6.     $username = trim($_POST['username']);
  7.     $password = trim($_POST['password']);
  8.     $stmt = $db->prepare("SELECT * FROM xail_users WHERE username = :username");
  9.     $params = array("username" => $username);
  10.     $stmt->execute($params);
  11.     $user = $stmt->fetch(PDO::FETCH_ASSOC);
  12.    
  13.     // Check if a user exists.
  14.     if ($user['username']) {
  15.         if (crypt($password, $user['password']) == $user['password']) {
  16.         // Success login.
  17.             $_SESSION['username'] = $user['username'];
  18.             switch ($user['role']) {
  19.                 case 1: $_SESSION['role'] = "Super Admin";
  20.                 break;
  21.                 case 2: $_SESSION['role'] = "Admin";
  22.                 break;
  23.                 default: $_SESSION['role'] = "Admin";
  24.             }
  25.             redirect_to("index.php");
  26.         } else {
  27.         // Failed login.
  28.         $login_handler = output_message("Wrong username or password!", "error");
  29.         }
  30.     } else {
  31.         $login_handler = output_message("Username {$username} doesn't exist.", "error");
  32.     }
  33. } else { // Form not submitted.
  34.     $username = "";
  35.     $password = "";
  36. } ?>
Add Comment
Please, Sign In to add comment