justhrun

cara_1.pehape

Aug 17th, 2014
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. <?php
  2. // cara_1 : desentralisasi
  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.         $is_admin = true;
  11.         $query  = "select id_admin from tabel_admin where username='$username' and password='$password'";
  12.         $result = mysql_query($query);
  13.         $rows = mysql_num_rows($result);
  14.  
  15.         if($rows!=1) {  // hanya boleh ada 1row
  16.                 $is_admin = false;
  17.         } else {
  18.                 //daftarkan ID jika user dan password BENAR
  19.                 list($id_admin) = mysql_fetch_row($result);
  20.                 mysql_free_result($result);
  21.                 $_SESSION['id_admin']=$id_admin;
  22.                 $_SESSION['username']=$username;
  23.                 echo "<script> document.location.href='operator/home.php'; </script>";
  24.         }
  25.  
  26.         if(!$is_admin) {        // di tabel_admin gk valid, cek ke table dosen
  27.                 $query = "select nip from tabel_dosen where username='$username' and password='$password'");
  28.                 $result = mysql_query($query);
  29.                 $rows = mysql_num_rows($result);
  30.  
  31.                 if($rows!=1) {  // hanya boleh ada 1row
  32.                         echo "<script> document.location.href='index.php?status=Username/Password Anda salah!'; </script>";
  33.                 } else {
  34.                         //daftarkan ID jika user dan password BENAR
  35.                         list($nip) = mysql_fetch_row($result);
  36.                         mysql_free_result($result);
  37.                         $_SESSION['nip']=$id_admin;
  38.                         $_SESSION['username']=$username;
  39.                         echo "<script> document.location.href='dosen/index.php'; </script>";
  40.                 }
  41.         }
  42.  
  43.         unset($_POST['login']);
  44. }
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment