Advertisement
Guest User

cookie

a guest
Aug 21st, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. <?php
  2. //jalankan session
  3. session_start();
  4.  
  5. require 'function.php';
  6.  
  7. if (isset($_COOKIE['id']) && isset($_COOKIE['key']) ) {
  8.     # code...
  9.    $id = $_COOKIE['id'];
  10.     $key = $_COOKIE['key'];
  11.  
  12.     $result = mysqli_query($conn,"SELECT username FROM user WHERE id = $id");
  13.     $row = mysqli_fetch_assoc($result);
  14.  
  15.     //cek cookie dan username
  16.     if ($key === hash('ripemd160', $row['username'])) {
  17.         # code...
  18.        $_SESSION['login1'] = true;
  19.     }
  20.  
  21. }
  22.  
  23. if (isset($_SESSION["login1"])) {
  24.     # code...  
  25.    echo "
  26.         <script>
  27.            alert('Anda Telah Login!!');
  28.            window.location='index.php';
  29.        </script>
  30.    ";
  31. }
  32.  
  33.  
  34. if (isset($_POST["login"])) {
  35.     # code...
  36.    //menangkap user dan passwordnya
  37.     $username = $_POST["username"];
  38.     $password = $_POST["password"];
  39.  
  40.     $result = mysqli_query($conn,"SELECT * FROM user WHERE username ='$username' ");
  41.  
  42.     if (mysqli_num_rows($result) === 1 ) {
  43.         # code...  
  44.        //satu berarti ada, kalo ada cek password
  45.         //cek password
  46.  
  47.         $row = mysqli_fetch_assoc($result);
  48.  
  49.         if (password_verify($password, $row["password"])) {
  50.             # code...
  51.            //set session
  52.             $_SESSION["login1"] = true;
  53.  
  54.             //cek remember me
  55.             if (isset ($_POST["remember"])) {
  56.                 # code...
  57.                //buat cookie
  58.                 setcookie('id',$row["id"], time()+180);
  59.                 setcookie('key', hash('ripemd160',$row["username"], time()+180));
  60.             }
  61.  
  62.  
  63.  
  64.             header("location: index.php");
  65.             exit;
  66.         }
  67.     }
  68.     $error = true;
  69. }
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement