SHARE
TWEET

session

eladha Dec 13th, 2016 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. session_start();
  3. error_reporting(0);
  4.  
  5. ############################ [Start connect] ###########################
  6.     $connect = new mysqli("localhost","root","","tut_php");
  7.         if($connect->connect_error){
  8.             die("Error conect:".$connect->connect_error);
  9.         }
  10. ############################ [End connect] #############################
  11.  
  12.  
  13. ############################ [Start Logout] ###########################################
  14. if($_GET['type'] == 'logout'){
  15.     session_destroy();
  16.     echo'<center><h3 class="ok">Please Wait .. Redirect after 3 sec ..</h3></center>';
  17.     echo'<meta http-equiv="refresh" content="3;url=session.php">';
  18. }
  19. ############################ [End Logout] ##############################################
  20.  
  21.  
  22. ############################ [End Login] ###############################################
  23.  
  24. if(isset($_POST['login'])){
  25.     $user = $_POST['user'];
  26.     $pass = md5($_POST['pass']);
  27.    
  28.     if(empty($user) and empty($pass)){
  29.         echo'Please insert all information and try again';
  30.     }else{
  31.         $query_ad = $connect->query("select * from admin where user = '".$user."' and pass = '".$pass."'");
  32.         if(mysqli_num_rows($query_ad) > 0){
  33.             $fetch_l = $query_ad->fetch_object();
  34.             $g_user = $fetch_l->user;
  35.             $g_pass = md5($fetch_l->pass);
  36.            
  37.             if($user != $g_user and $pass != $g_pass){
  38.                 echo'<h2>Sorry the information incorrect .. Please try again</h2>';
  39.             }else{
  40.                 $_SESSION['user'] = $user;
  41.                 echo'<center><h3 class="ok">Please Wait .. Redirect after 3 sec ..</h3></center>';
  42.                 echo'<meta http-equiv="refresh" content="3;url=session.php">';
  43.             }
  44.         }  
  45.     }
  46. }
  47. $usern = $_SESSION['user'];
  48. if(empty($usern)){
  49.     echo'<form action="session.php" method="post">
  50.         Username : <input type="text" name="user"><br>
  51.         Password : <input type="password" name="pass"><br>
  52.         <input type="submit" name="login" value="Login" />
  53.         </form>';
  54. }else{
  55.     echo 'welcome : '.$usern;
  56.     echo'<br><a href="?type=logout">Logout</a>';
  57. }
  58.  
  59. ############################ [End Login] ###############################################
  60.  
  61. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top