Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.55 KB | None | 0 0
  1. <?php session_start(); $ref = $_SERVER['HTTP_REFERER'];
  2.  
  3. if(isset($_SESSION['username'])) {
  4.  
  5.     include('header.php');
  6.     echo '<div class="error_message">Attention! You are already logged in.</div>';
  7.     echo "<h2>What to do now?</h2><br />";
  8.     echo "Go <a href='javascript:history.go(-1)'>back</a> to the page you were viewing before this.</li>";
  9.     include('footer.php');
  10.    
  11.     exit();
  12. }
  13.  
  14. // Has an error message been passed to login.php?
  15. $error = $_GET['e'];
  16.  
  17. if($error == 1) {
  18.     $error = '<div class="error_message">Attention! You must be logged in to view this page.</div>';
  19. }
  20.  
  21. // Only process if the login form has been submitted.
  22. die(var_dump($_POST, $_SESSION));
  23. if(isset($_POST['login'])) {
  24.  
  25.     $username = $_POST['username'];
  26.     $password = $_POST['password'];
  27.  
  28.     if (!isset($username) || !isset($password)) {
  29.         header( "Location: home.php" ); exit();
  30.     } elseif (empty($username) || empty($password)) {
  31.         $error = '<div class="error_message">Attention! Please enter your Username and Password.</div>';
  32.     } else {
  33.    
  34.     // Add slashes to the username and md5() the password
  35.     $user = mysql_real_escape_string(addslashes($_POST['username']));
  36.     $pass = mysql_real_escape_string(md5($_POST['password']));
  37.    
  38.    
  39.     $sql = "SELECT * FROM login_users WHERE username='$user' AND password='$pass'";
  40.     $result = mysql_query($sql);
  41.    
  42.     // Check that at least one row was returned
  43.     $rowCheck = mysql_num_rows($result);
  44.    
  45.     if($rowCheck > 0) {
  46.     while($row = mysql_fetch_array($result)) {
  47.    
  48.       // Start the session and register a variable
  49.    
  50.       session_start();
  51.       $_SESSION['username'] = $user;
  52.       //session_register('username');
  53.          
  54.       header("Location: ".$ref); exit();
  55.    
  56.       }
  57.    
  58.       } else {
  59.    
  60.       // If nothing is returned by the query, unsuccessful login code goes here...
  61.    
  62.       $error = '<div class="error_message">Attention! Incorrect username or password.</div>';
  63.       }
  64.     }
  65. }
  66.  
  67. if(stristr($_SERVER['PHP_SELF'], 'admin')) { include('../header.php'); } else { include('header.php'); }
  68.  
  69. echo $error; ?>
  70.  
  71. <h2>Login</h2>
  72.  
  73. <form method="POST" action="">
  74. <label>Username</label><input type="text" name="username" size="20">
  75. <br />
  76. <label>Password</label><input type="password" name="password" size="20">
  77. <br />
  78. <input type="submit" value="Submit" name="login">
  79. </form>
  80.  
  81. <p><a href="forgotten.php">Forgotten Password?</a></p>
  82.  
  83. <p>Not registered yet? It's free, quick & easy to do so <a href="sign_up.php">here</a></p>
  84.  
  85. <?php if(stristr($_SERVER['PHP_SELF'], 'admin')) { include('../footer.php'); } else { include('footer.php'); } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement