Advertisement
arijulianto

Login dan Logout dengan Mencatat Log Aktivitas

Feb 7th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.02 KB | None | 0 0
  1. // file login.php
  2. <?php
  3. session_start();
  4. include "../connect_db.php";
  5. include "../function.php";
  6. $ref = urldecode($_GET['next']);
  7. $loc = $ref ? $ref : "home";
  8. $now = date("Y-m-d H:i:s");
  9.  
  10. if(isset($_POST['login'])){
  11.     $username = escape(strtolower($_POST['user']));
  12.     $password = md5($_POST['pass']);
  13.     $userfiltered = str_replace(array(" ","-","_","."),"",strtolower($username));
  14.     $usermail = strpos($username,"@") ? "email='$username'" : "lower(username)='$username'";
  15.    
  16.  
  17.     if(trim($_POST['user'])=="" && trim($_POST['pass']=="")){
  18.         $msg = "Silahkan isi Username dan Password untuk login...!";
  19.         $cek = "blok kosonguser pass";
  20.     }else{
  21.         $sql = mysql_query("SELECT * from users where $usermail AND password='$password'") or die(mysql_error());
  22.         $sql2 = mysql_query("SELECT * from users where $usermail");
  23.  
  24.         if(mysql_num_rows($sql)>0 && mysql_num_rows($sql2)>0){
  25.             $data = mysql_fetch_array($sql);
  26.             if($data['aktif']==1){
  27.             $_SESSION['x_uid'] = $data['uid'];
  28.             $_SESSION['x_username'] = $data['username'];
  29.             $_SESSION['x_nama'] = $data['nama'];
  30.             $_SESSION['x_level'] = $data['level'];
  31.             $_SESSION['fail'][$username] = 0;
  32.             mysql_query("INSERT into log(uid,ip,tgl,aktivitas) VALUES('$data[uid]','$_SERVER[REMOTE_ADDR]','$now','login ke Admin Panel')");
  33.             header("location:$loc");
  34.             }else{
  35.             $msg = "Maaf... Login Anda tertolak!<br />Akun Anda sedang tidak aktif atau diblokir. Silahkan hubungi Administrator untuk mengaktifkan akun Anda.";
  36.             }
  37.         }else{
  38.             $msg = "Username atau Password salah...!";
  39.         }
  40.     }
  41. }
  42.  
  43. if($_SESSION['x_uid']){
  44.     header("location:$loc");
  45.     exit;
  46. }
  47.  
  48. ?><DOCTYPE html>
  49. <html>
  50. <head>
  51. <title>Login</title>
  52. <style type="text/css">
  53. form{
  54.     margin:0;
  55. }
  56. .header{
  57.     height:80px;
  58. }
  59. .header h1{
  60.     margin:20px 0px;
  61. }
  62. .login{
  63.     width:400px;
  64.     margin:15px auto;
  65.     background:#fff;
  66.     border:1px solid #e0e0e0;
  67.     font-family:microsoft sans serif,helvetica,arial,tahoma;
  68.     font-size:14px;
  69. }
  70. .login-top{
  71.     padding:18px 12px;
  72. }
  73. .login-top p{
  74.     overflow:hidden;
  75.     width:320px;
  76.     margin:auto;
  77. }
  78. .login-top p:last-child{
  79.     margin-top:8px;
  80. }
  81. .login-bottom{
  82.     background:#f5f5f5;
  83.     padding:10px 24px;
  84.     text-align:right;
  85.     border-top:1px solid #e5e5e5;
  86. }
  87. .input{
  88.     display:inline-block;
  89.     height:30px;
  90.     line-height:30px;
  91.     float:left;
  92.     width:200px;
  93.     background-color:#fff;border:1px solid #ccc;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border linear .2s,box-shadow linear .2s;-moz-transition:border linear .2s,box-shadow linear .2s;-o-transition:border linear .2s,box-shadow linear .2s;transition:border linear .2s,box-shadow linear .2s;
  94.     -webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0;padding:4px 6px;
  95. }
  96. .input:focus{
  97.     border-color:rgba(82,168,236,0.8);outline:0;outline:thin dotted \9;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6)
  98. }
  99. .add-on{
  100.     display:inline-block;
  101.     width:90px;
  102.     height:20px;
  103.     padding:4px 5px;
  104.     font-size:14px;
  105.     font-weight:normal;
  106.     line-height:20px;
  107.     text-align:right;
  108.     text-shadow:0 1px 0 #fff;
  109.     background-color:#eee;
  110.     border:1px solid #ccc;
  111.     border-radius: 4px 0px 0px 4px;
  112.     margin-right: -1px;
  113.     float:left
  114. }
  115. .icon-lock{background-position:-287px -24px}
  116. .icon-user{background-position:-168px 0}
  117. .msg{
  118.     padding:8px 0px;
  119.     text-align:center;
  120.     background:#f2eb9a;
  121.     border:1px solid #a99f2c;
  122.     color:#ff0000;
  123.     margin-bottom:10px;
  124. }
  125. </style>
  126. </head>
  127. <body>
  128. <div class="header">
  129. <div class="head-text">
  130. <h1>Login</h1>
  131. </div>
  132. </div>
  133. <div class="main">
  134.  
  135. <div class="login corner-all shadow">
  136. <form action="" method="post">
  137. <div class="login-top">
  138. <?php
  139. if(isset($_POST['login']) && $msg){
  140.     echo "<div class=\"msg\">$msg</div>";
  141. }else{
  142.     echo  "<div class=\"msg\">Silahkan login untuk mengakses halaman ini...!</div>";
  143. }
  144. ?>
  145. <p><label for="user" class="add-on">Username <img src="../images/spacer.png" class="icon-user" width="16" height="16" /></label><input type="text" name="user" id="user" class="input" placeholder="Username atau Email" value=<?php echo "\"",$_POST['user'],"\""; if(!$_POST['user']) echo " autofocus"; ?> /></p>
  146. <p><label for="pass" class="add-on">Password <img src="../images/spacer.png" class="icon-lock" width="16" height="16" /></label><input type="password" name="pass" id="pass" class="input" placeholder="Password"<?php if($_POST['user']) echo " autofocus"; ?> /></p>
  147. </div>
  148. <div class="login-bottom">
  149. <p><input type="submit" name="login" class="button large" value="Login" /></p>
  150. </div>
  151. </div>
  152. </form>
  153. </div>
  154. </div>
  155.  
  156. // file logout.php
  157. <?php
  158. session_start();
  159. include "connect_db.php";
  160. $now = date("Y-m-d H:i:s");
  161. if($_SESSION['x_uid'])mysql_query("INSERT into log(uid,ip,tgl,aktivitas) VALUES('$_SESSION[x_uid]','$_SERVER[REMOTE_ADDR]','$now','logout dari Admin Panel')");
  162. session_destroy();
  163. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement