Advertisement
khoirul_anwar

index.php

Jun 3rd, 2017
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.48 KB | None | 0 0
  1. <?php
  2.  
  3.   require 'config.php';
  4.  
  5.   if ( isset($_POST['submit']) ) {
  6.     $username = mysqli_real_escape_string($connection, trim($_POST['username']) );
  7.     $password = mysqli_real_escape_string($connection, trim($_POST['password']) );
  8.  
  9.     $sql = mysqli_query($connection, " SELECT username, password FROM user WHERE username='$username' ");
  10.     list($username, $passwd) = mysqli_fetch_array($sql);
  11.     $row = mysqli_num_rows($sql);
  12.     if ($row > 0) {
  13.       if ( password_verify($password, $passwd) ) {
  14.         session_start();
  15.         $_SESSION['username'] = "$username";
  16.         $_SESSION['status']   = "login";
  17.         header("Location:landing/home.php");
  18.       } else {
  19.         header("Location:index.php?message=login_failed");
  20.       }
  21.  
  22.     } else {
  23.       echo "Username doesn't exists!";
  24.     }
  25.  
  26.   }
  27.  
  28.  ?>
  29.  
  30.  
  31. <?php
  32.  
  33.   session_start();
  34.   if (isset($_SESSION['status']) == "login") {
  35.     header("Location:landing/home.php");
  36.   }
  37.  
  38.  ?>
  39.  
  40.  
  41. <!DOCTYPE html>
  42. <html>
  43.   <head>
  44.     <meta charset="utf-8">
  45.     <title>Login</title>
  46.   </head>
  47.   <body>
  48.     <form action="" method="post">
  49.       <div>
  50.         <label>Username</label>
  51.         <input type="text" name="username" placeholder="username" required>
  52.       </div>
  53.       <div>
  54.         <label>Password</label>
  55.         <input type="password" name="password" placeholder="password" required>
  56.       </div>
  57.       <div>
  58.         <input type="submit" name="submit" value="Log In">
  59.       </div>
  60.     </form>
  61.   </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement