Advertisement
Guest User

login

a guest
May 18th, 2016
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. //Login.php
  2. include("../include/config.php");
  3.     if(isset($_POST['login'])){
  4.         $username = $_POST['username'];
  5.         $password = $_POST['password'];
  6.         $pswd =  sha1($password);
  7.         $timeupdate = date('H:i:s Y-m-d');
  8.         $ip = $_SERVER['REMOTE_ADDR'];
  9.         $query = "SELECT * FROM admin_login WHERE user = '".$username."' AND pswd = '".$pswd."' ";
  10.         $qstatement = $pdo->prepare($query);
  11.         $qstatement->execute(array($username, $password));
  12.      
  13.         if($qstatement->rowCount() == 1){
  14.             $_SESSION['username'] = $username;
  15.             $loginupdate = "UPDATE admin_login SET login_status = ? , IP = ? WHERE user = ?";
  16.             $updatestmnt = $pdo->prepare($loginupdate);
  17.             $updatestmnt->execute(array($timeupdate, $ip, $username));
  18.         }
  19.         if(@$_SESSION['username']):
  20.             if(headers_sent()):?>
  21.                 <meta http-equiv='Refresh' content="1; url=dashboard.php"/>
  22.                 <?php
  23.                 else:
  24.                     header('Location: dashboard.php');
  25.                 endif;
  26.         else:
  27.         echo 'wrong username/password';
  28.         endif;
  29.  
  30.     }
  31.     ?>
  32. //home.php
  33. <?php
  34.     include ("../include/config.php");
  35.     session_start();
  36.     if($_SESSION['username'])){
  37.        
  38.    
  39. ?>
  40. <html>
  41.       <head>
  42.           <title>home</title>
  43.       </head>
  44. <body>
  45.   <h3>Dashboard</h3>
  46.  
  47. <hr>
  48.   <h2>
  49.       <?php
  50.           echo "WelCome : " .$_SESSION['username'];
  51.       ?>
  52.   </h2>
  53. <h2><a href="index.php?logout">Logout</a> </h2>
  54. </body>
  55. </html>
  56.  
  57. <?php
  58. }
  59. else
  60. echo "kindly login to continue";
  61. ?>
  62. //logout.php
  63. <?php
  64. session_start();
  65. session_destroy();
  66. unset($_SESSION['username']);
  67. header("location:login.php")
  68.  
  69.  
  70.  
  71. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement