Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if ( isset($_SESSION["login"]) ){
- header("Location: index.php");
- }
- require 'functions.php';
- if ( isset($_POST["login"]) ) {
- $username = $_POST["username"];
- $password = $_POST["password"];
- $result = mysqli_query($conn, "SELECT * FROM user WHERE username = '$username'");
- // cek username
- if( mysqli_num_rows($result) === 1 ) {
- // cek password
- $row = mysqli_fetch_assoc($result);
- if (password_verify($password, $row["password"]) ) {
- // cek session
- $_SESSION["login"] = true;
- header("Location: index.php");
- exit;
- }
- }
- $error = true;
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title> Login </title></head>
- <body>
- <h1>Halaman Login</h1>
- <form action="" method="post">
- <ul><br>
- <li>
- <label for="username">Username :</label><br>
- <input type="text" name="username" id="username" autocomplete="off" placeholder="masukkan username .. "/>
- </li>
- <li>
- <label for="password">Password :</label><br>
- <input type="password" name="password" id="password" autocomplete="off" placeholder="masukkan password ... "/>
- </li><br>
- <?php if( isset($error) ) : ?>
- <p style="color: red; font-style: italic;">username/password salah</p>
- <?php endif; ?>
- <button type="submit" name="login">Login</button><br></br>
- </ul>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement