Advertisement
cdsatrian

belajar session

Sep 24th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 KB | None | 0 0
  1. /*******************/
  2. FILE: login.php
  3.  
  4. <table width="429" border="0" align="center" cellpadding="0" cellspacing="0">
  5.   <tr>
  6.     <td width="429" height="15" bgcolor="#333333"><h3 align="center" class="style1">PORTAL SISTEM  AKADEMIKA </h3></td>
  7.   </tr>
  8.   <tr>
  9.     <td height="162" bgcolor="#CCCCCC">
  10.         <form action="proses.php" method="post">
  11.           <div align="justify"></div>
  12.           <table width="310" border="0" align="center" cellpadding="0" cellspacing="0">
  13.             <tr>
  14.               <td width="97"><span class="style4">Username </span></td>
  15.               <td width="267">
  16.                 <input type="text"
  17.                        name="username"
  18.                        size="25"
  19.                        placeholder="Masukan Username Anda" />
  20.               </td>
  21.             </tr>
  22.             <tr>
  23.               <td height="41"><span class="style4">Password </span></td>
  24.               <td>
  25.                  <input type="password"
  26.                         name="password"
  27.                         size="25"
  28.                         placeholder="Masukan Password Anda"/>
  29.               </td>
  30.             </tr>
  31.             <tr>
  32.               <td>&nbsp;</td>
  33.               <td><input type="submit" name="submit" value="LOGIN"></td>
  34.             </tr>
  35.           </table>
  36.         </form>
  37.     </td>
  38.   </tr>
  39. </table>
  40.  
  41. /*******************/
  42. FILE: process.php
  43.  
  44. <?php
  45. session_start(); //memulai session
  46. include "konek.php";
  47. $msg='';
  48. // check submit
  49. if(isset($_POST['submit']))
  50. {
  51.   //query untuk mengambil data user dari database sesuai dengan username inputan form
  52.   $sql = "SELECT level,username
  53.          FROM user
  54.          WHERE username = '".$_POST['username']."' AND password='".$_POST['password']."'";
  55.   if($result = mysql_query($sql))
  56.   {
  57.     if (mysql_num_rows($result)==1)
  58.     {
  59.       //menyimpan tipe user dan username dalam session
  60.       $_SESSION['level'] = $data['level'];
  61.       $_SESSION['username'] = $data['username'];
  62.       //redirect halaman sesuai 'level'-nya
  63.       header('location:'.$data['level'].'/home_'.$data['level'].'.php');
  64.     }
  65.     //jika password/username tidak sesuai
  66.     else
  67.     {
  68.     $msg='Username / Password Salah atau tidak ditemukan';
  69.     }
  70.   }
  71.   else
  72.   {
  73.     $msg='Terjadi kesalahan pada database';
  74.   }
  75. }
  76. else
  77. {
  78.   $msg='Anda tidak berhak mengakses halaman ini langsung';
  79. }
  80. echo "<center><font color='red'>$msg</font><br><a href='index.php'>Kembali</a></center>";
  81. ?>
  82.  
  83. /*******************/
  84. FILE: session.php
  85. <?php
  86. session_start();
  87. if ($_SESSION['level'] == "admin")
  88. {
  89.   header('location:admin/home_admin.php');
  90. }
  91. elseif ($_SESSION['level'] == "user")
  92. {
  93.   header('location:user/home_user.php');
  94. }
  95. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement