Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- require 'functions.php';
- //cek cookie
- if(isset($_COOKIE['id']) && isset($_COOKIE['key']) ){
- $id = $_COOKIE['id'];
- $key = $_COOKIE['key'];
- //ambil username berdasarkan id
- $result= mysqli_query($conn, "SELECT username FROM user WHERE id='$id'");
- $row = mysqli_fetch_assoc($result);
- //cek cookie dan username
- if ($key === hash('sha256', $row['username'])) {
- $_SESSION['login'] = true;
- }
- }
- //cek tombol masuk sudah ditekan atau belum
- if ( isset($_POST["masuk"])) {
- $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']))
- //set session
- $_SESSION["login"]= true;
- // header("Location: index.php");
- // exit;
- // }
- }
- //cek remember me
- if (isset($_POST["remember"])) {
- //buat cookie
- setcookie('id', $row['id'], time()+60);
- setcookie('key', hash('sha256',$row['username']), time()+60);
- if ($_POST["username"] == "admin" && $_POST["password"] == "admin") {
- header("Location: indexadmin.php");
- exit;
- } else {
- header("Location: index.php");
- exit;
- }
- }
- }
- if (isset($_SESSION["login"])) {
- if ($_POST["username"] == "admin" && $_POST["password"] == "admin") {
- header("Location: indexadmin.php");
- exit;
- } else {
- header("Location: index.php");
- exit;
- }
- }
- if (isset($_POST["daftar"])) {
- header("Location: registrasi.php");
- exit;
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Halaman Login</title>
- <link rel="stylesheet" href="../css/login.css">
- </head>
- <body>
- <h2>LibrarIH</h2>
- <h1>selamat datang <br>di perpustakaan <br>itikurih hibarna</h1>
- <?php if (isset($error)): ?>
- <p style="color:red; font-style:italic">Username/password salah!</p>
- <?php endif; ?>
- <form class="form" action="" method="post">
- <input type="text" name="username" id="username" placeholder="nama pengguna">
- <input type="password" name="password" id="password" placeholder="kata sandi"><br>
- <td>
- <input type="checkbox" name="remember" id="remember">
- <label class="remember"for="remember">Ingat Saya</label></td><br>
- <button "button"type="submit" name="masuk">masuk</button> <br>
- <label for="daftar">belum punya akun?</label> <br>
- <a href="../nyoba/registrasi.php"><button type="submit" name="daftar"> daftar</button></a>
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment