Advertisement
Guest User

login

a guest
Nov 17th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. if ( isset($_SESSION["login"]) ){
  5.     header("Location: index.php");
  6. }
  7. require 'functions.php';
  8. if ( isset($_POST["login"]) ) {
  9.  
  10.     $username = $_POST["username"];
  11.     $password = $_POST["password"];
  12.     $result = mysqli_query($conn, "SELECT * FROM user WHERE username = '$username'");
  13.  
  14.     // cek username
  15.     if( mysqli_num_rows($result) === 1 ) {
  16.         // cek password
  17.         $row = mysqli_fetch_assoc($result);
  18.         if (password_verify($password, $row["password"]) ) {
  19.             // cek session
  20.             $_SESSION["login"] = true;
  21.  
  22.             header("Location: index.php");
  23.             exit;
  24.         }
  25.     }
  26.     $error = true;
  27. }
  28.  
  29. ?>
  30.  
  31.  
  32.  
  33. <!DOCTYPE html>
  34. <html>
  35. <head>
  36. <title> Login </title></head>
  37. <body>
  38.     <h1>Halaman Login</h1>
  39.  
  40. <form action="" method="post">
  41.     <ul><br>
  42.         <li>
  43.             <label for="username">Username :</label><br>
  44.             <input type="text" name="username" id="username" autocomplete="off" placeholder="masukkan username .. "/>
  45.         </li>
  46.         <li>
  47.             <label for="password">Password :</label><br>
  48.             <input type="password" name="password" id="password" autocomplete="off" placeholder="masukkan password ... "/>
  49.         </li><br>
  50.         <?php  if( isset($error) ) : ?>
  51.     <p style="color: red; font-style: italic;">username/password salah</p>
  52. <?php endif; ?>
  53.         <button type="submit" name="login">Login</button><br></br>
  54.        
  55.     </ul>
  56.  
  57. </form>
  58. </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement