Guest User

Untitled

a guest
Aug 9th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php session_start(); //using PHP sessions
  2.  
  3.  
  4. require 'connect.php';
  5. include 'header.inc.php';
  6.  
  7. if ($_POST['login']=='Submit') {
  8.     $username= $_POST['username'];
  9.     $password= $_POST['password'];
  10.    
  11.     //store the username   
  12.     $_SESSION['username']=$username;
  13.    
  14.     $sql="SELECT * FROM users WHERE username='$username' AND password='$password'";
  15.     $result = $conn->query($sql) or die(mysqli_error());
  16.  
  17.     $count = $result->num_rows;
  18.         if($count==1) // If there is a match..
  19.         {
  20.             header("Location:overviewpage.php"); // go to overview page                    
  21.            
  22.     //      $_SESSION["username"] = $username; // Creates a cookie saving the username
  23.     //      $_SESSION["loggedIn"] = true; // Creates a cookie saying the user is logged in
  24.     //      header("Location:ProtectedPage.php");
  25.         }else{ // If invalid information was entered
  26. //          header("Location:overviewpage.php"); // Lastly, redirect back to login page
  27.             echo 'invalid username or password. Please try again.';
  28.             echo printLoginForm();
  29.            
  30.         }
  31.  
  32. }
  33. else {
  34.     printLoginForm();
  35. }
  36.  
  37. function printLoginForm() {
  38.     echo '<form id="form1" name="form1" method="post" action="index.php">
  39.       <p>
  40.         <label for="username">username</label>
  41.         <input type="text" name="username" id="username" />
  42.    
  43.         <label for="password">password</label>
  44.         <input type="password" name="password" id="password" />
  45.    
  46.         <input type="submit" name="login" id="login" value="Submit" />
  47.       </p>
  48.     </form>';
  49. }
  50.  
  51. ?>
  52.  
  53.  
  54.  
  55. <p>&nbsp;</p>
  56. </body>
  57. </html>
Add Comment
Please, Sign In to add comment