Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(0);
- $koneksi = new mysqli("localhost","root","","a4_db");
- if($_SESSION['admin'] || $_SESSION['kasir'] ) {
- header("location:index.php");
- } else {
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
- <title>Halaman Login</title>
- </head>
- <body>
- <h2>Halaman login</h2>
- <form action="" method="POST">
- <ul>
- <li>
- <label>Username</label>
- <input type="text" name="username" placeholder="Username">
- </li>
- </ul>
- <ul>
- <li>
- <label>Password</label>
- <input type="password" name="password" placeholder="Password">
- </li>
- </ul>
- </form>
- <?php
- $username = $_POST['username'];
- $password = $_POST['password'];
- if( isset($_POST['login']) ) {
- $sql = $koneksi->query("select * from tb_user where user_id='$username' and pass='$password' ");
- $result = $sql->num_rows;
- $data = $sql->fetch_assoc();
- if( $result > 0 ) {
- if(password_verify($password, $data['pass'])) {
- session_start();
- $_SESSION['username'] = $data['user_id'];
- $_SESSION['pass'] = $data['pass'];
- $_SESSION['level'] = $data['level'];
- if($data['level'] == "admin") {
- $_SESSION['admin'] = $data[id];
- header("location:index.php");
- }else if($data['level'] == "kasir") {
- $_SESSION['kasir'] = $data[id];
- header("location:index.php");
- }
- } else {
- ?>
- <script>
- alert("Login Gagal Username dan Password Salah!!");
- </script>
- <?php
- }
- }
- ?>
- </body>
- </html>
- <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement