justhrun

cara_2.pehape

Aug 17th, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. <?php
  2. // cara_2 : sentralisasi
  3. session_start();
  4.  
  5. if(isset($_POST['login'])){
  6.         include ("inc/koneksi.php");
  7.         $username=htmlentities((trim($_POST['username'])));
  8.         $password=htmlentities(md5($_POST['password']));
  9.  
  10.         $query  = "select id_admin,level from tabel_admin where username='$username' and password='$password'";
  11.         $result = mysql_query($query);
  12.         $rows = mysql_num_rows($result);
  13.  
  14.         if($rows!=1) {  // hanya boleh ada 1row
  15.                 echo "<script> document.location.href='index.php?status=Username&/Password Anda salah!'; </script>";
  16.         } else {
  17.                 //daftarkan ID jika user dan password BENAR
  18.                 list($id_admin,$level) = mysql_fetch_row($result);
  19.                 mysql_free_result($result);
  20.                 $_SESSION['id_admin']=$id_admin;
  21.                 $_SESSION['username']=$username;
  22.                 $_SESSION['level']=$level;
  23.  
  24.                 switch($level {
  25.                         case 1: echo "<script> document.location.href='operator/home.php'; </script>"; break;
  26.                         case 2: echo "<script> document.location.href='dosen/index.php'; </script>"; break;
  27.                         case 3: echo "<script> document.location.href='mahasiswa/home.php'; </script>"; break;
  28.                         case 4: echo "<script> document.location.href='opisboy/home.php'; </script>"; break;
  29.                         case 5: echo "<script> document.location.href='satpam/home.php'; </script>"; break;
  30.                 }
  31.  
  32.         }
  33.  
  34.         unset($_POST['login']);
  35. }
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment