Advertisement
Guest User

login.php

a guest
Apr 25th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 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.  
  39. if( isset($_POST['login']) ) {
  40.  
  41. $sql = $koneksi->query("select * from tb_user where user_id='$username' and pass='$password' ");
  42.  
  43. $result = $sql->num_rows;
  44. $data = $sql->fetch_assoc();
  45.  
  46. if( $result > 0 ) {
  47.  
  48. if(password_verify($password, $data['pass'])) {
  49.  
  50. session_start();
  51.  
  52. $_SESSION['username'] = $data['user_id'];
  53. $_SESSION['pass'] = $data['pass'];
  54. $_SESSION['level'] = $data['level'];
  55.  
  56. if($data['level'] == "admin") {
  57. $_SESSION['admin'] = $data[id];
  58. header("location:index.php");
  59.  
  60. }else if($data['level'] == "kasir") {
  61. $_SESSION['kasir'] = $data[id];
  62. header("location:index.php");
  63. }
  64.  
  65. } else {
  66.  
  67. ?>
  68. <script>
  69. alert("Login Gagal Username dan Password Salah!!");
  70. </script>
  71. <?php
  72.  
  73. }
  74.  
  75. }
  76.  
  77. ?>
  78.  
  79. </body>
  80. </html>
  81.  
  82. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement