Advertisement
michaelyuen

Untitled

Jun 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors',1);
  3. error_reporting(E_ALL);
  4. session_start();
  5. include('connection.php');
  6. if(isset($_POST['submit'])) {
  7.     $username = $_POST['username'];
  8.     $password = $_POST['password'];
  9.     $query = "SELECT * FROM hash WHERE username = '$username' LIMIT 1";
  10.     // use LIMIT 1 so query will stop once match record is found
  11.     $result = mysqli_query($conn , $query) or die(mysqli_error($conn));
  12.     if (mysqli_num_rows($result) == 1) {
  13.         // you don't need a while loop for one record
  14.         $row = mysqli_fetch_assoc($result);
  15.         $upass = $row['password'];
  16.         $uname = $row['username'];
  17.         $uid = $row['id'];
  18.         if (password_verify($password, $upass)) {
  19.         $_SESSION['active'] = $uid;
  20. header('location:welcome.php');
  21.         }  
  22.     } else {
  23.     echo "<script>alert('error');
  24.     window.location.href= 'index.php';</script>";
  25.     }
  26. } else {
  27.     echo "<script>alert('INVALID USERNAME OR PASSWORD!');
  28.     window.location.href= 'index.php';</script>";
  29. }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement