Advertisement
Guest User

login.php

a guest
Apr 25th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3. $koneksi = new mysqli("localhost","root","","a4_db");
  4.  
  5. if($_SESSION['admin'] || $_SESSION['kasir'] ) {
  6. header("location:index.php");
  7. } else {
  8. ?>
  9.  
  10. <!DOCTYPE html>
  11. <html>
  12. <head>
  13. <meta charset="UTF-8">
  14. <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  15. <title>Halaman Login</title>
  16. </head>
  17. <body>
  18. <h2>Halaman login</h2>
  19. <form action="" method="POST">
  20. <ul>
  21. <li>
  22. <label>Username</label>
  23. <input type="text" name="username" placeholder="Username">
  24. </li>
  25. </ul>
  26. <ul>
  27. <li>
  28. <label>Password</label>
  29. <input type="password" name="password" placeholder="Password">
  30. </li>
  31. </ul>
  32. </form>
  33.  
  34. <?php
  35.  
  36. $username = $_POST['username'];
  37. $password = $_POST['password'];
  38. // $login = $_POST['login'];
  39.  
  40. if( isset($_POST['login']) ) {
  41.  
  42. $sql = $koneksi->query("select * from tb_user where user_id='$username' and pass='$password' and status='Aktif' ");
  43.  
  44. $result = $sql->num_rows;
  45. $data = $sql->fetch_assoc();
  46.  
  47. if( $result > 0 ) {
  48.  
  49. if(password_verify($password, $data['pass'])) {
  50.  
  51. session_start();
  52.  
  53. $_SESSION['username'] = $data['user_id'];
  54. $_SESSION['pass'] = $data['pass'];
  55. $_SESSION['level'] = $data['level'];
  56.  
  57. if($data['level'] == "admin") {
  58. $_SESSION['admin'] = $data[id];
  59. header("location:index.php");
  60.  
  61. }else if($data['level'] == "kasir") {
  62. $_SESSION['kasir'] = $data[id];
  63. header("location:index.php");
  64.  
  65. }
  66.  
  67. } else {
  68.  
  69. ?>
  70. <script>
  71. alert("Login Gagal Username dan Password Salah!!");
  72. </script>
  73. <?php
  74.  
  75. }
  76.  
  77. }
  78.  
  79. ?>
  80.  
  81. </body>
  82. </html>
  83.  
  84. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement