SHARE
TWEET

cek_login.php

mfauziproject Apr 2nd, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     //mengaktifkan session pada php
  3.     session_start();
  4.  
  5.     //menghubungkan php dengan koneksi database
  6.     include 'koneksi.php';
  7.  
  8.     //menangkap data yang dikirimkan dari form login
  9.     $username = $_POST['username'];
  10.     $password = $_POST['password'];
  11.  
  12.     //menyeleksi data user dengan username dan password yang sesuai
  13.     $login = mysqli_query($koneksi, "select * from tb_user where username='$username' and password='$password'");
  14.  
  15.     //menghitung jumlah data yang ditemukan
  16.     $cek = mysqli_num_rows($login);
  17.  
  18.     //cek apakah username dan password di temukan pada database
  19.     if($cek > 0){
  20.         $data = mysqli_fetch_assoc($login);
  21.         //cek jika user login sebagai admin
  22.         if($data['level']=="admin"){
  23.             //buat session login dan username
  24.             $_SESSION['username'] = $username;
  25.             $_SESSION['level'] = "admin";
  26.             //alihkan ke halaman dashboard admin
  27.             header("location:halaman_admin.php");
  28.  
  29.             //cek jika user login sebagai user
  30.         }else if ($data['level']=="user") {
  31.             //buat session login dan username
  32.             $_SESSION['username'] = $username;
  33.             $_SESSION['level'] = "user";
  34.             //alihkan ke halaman dashboard user
  35.             header("location:halaman_user.php");
  36.         }else{
  37.             //alihkan ke halaman login kembali
  38.             header("location:index.php?pesan=gagal");
  39.         }
  40.     }
  41. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top