justhrun

cara_1.1.pehape

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