Guest User

Untitled

a guest
Apr 10th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.    
  4.     $username = $_REQUEST["txt_username"];
  5.     $password = $_REQUEST["txt_password"];
  6.     $action = $_GET["action"];
  7.    
  8.     $host = "127.0.0.1";
  9.     $user = "root";
  10.     $pass = "12157114";
  11.    
  12.     try {
  13.         $dbh = new PDO("mysql:host=$host;dbname=logansarchive", $user, $pass);
  14.         $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  15.     }
  16.     catch(PDOException $e) {
  17.         echo $e->getMessage();
  18.     }
  19.    
  20.     // Log in
  21.     $hashed_pass = hash("sha512", $password);
  22.    
  23.     $sql = "select count(*) as count, adminid, adminname, DATE_FORMAT(lastlogin, '%W, %M %e, %Y @ %h:%i %p' ) AS lastlogin from admin where adminname = :name and adminpass = :pass";
  24.     $result = $dbh->prepare($sql);
  25.    
  26.     $result->bindParam(":name", $username);
  27.     $result->bindParam(":pass", $hashed_pass);
  28.    
  29.     $stmt = $result->execute();
  30.     $row = $result->fetch();
  31.     if ($row["count"] == 1) {
  32.         session_start();
  33.         $_SESSION["adminid"] = $row["adminid"];
  34.         $_SESSION["adminname"] = $row["adminname"];
  35.         $_SESSION["lastlogin"] = $row["lastlogin"];    
  36.        
  37.         $dbh = null;
  38.         header("Location: /logansarchive/admin/index.php");
  39.     }
  40.     else {
  41.         $dbh = null;
  42.         header("Location: /logansarchive/admin/login.php?login_attempt=1");
  43.     }
  44.    
  45.     if ($action == "out") {
  46.         // Log out
  47.         $_SESSION["adminid"] = null;
  48.         $_SESSION["adminname"] = null;
  49.         $_SESSION["lastlogin"] = null; 
  50.         header("Location: /logansarchive/admin/login.php?logged_out=1");
  51.     };
  52. ?>
Add Comment
Please, Sign In to add comment