Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.  
  4.     // Check if the HTML form was submitted
  5.     if( !empty( $_POST["username"] ) ){
  6.         // The form was submitted
  7.         $username = $_POST["username"]; // The submitted input values
  8.         $password = $_POST["password"];
  9.  
  10.         // Connect to your mysql server
  11.         mysql_connect("localhost", "username", "password");
  12.         mysql_select_db("users_database");
  13.        
  14.         $results = mysql_query("SELECT * FROM USERS WHERE username = '$username' AND password = '$password'");
  15.  
  16.         // If there are more then 0 results then the username and password are correct
  17.         if( mysql_num_rows( $results ) ){
  18.             // Successful login, lets set the session
  19.             $_SESSION["username"] = $username;
  20.         } else {
  21.             // ELse output an error
  22.             echo "username and password are wrong fool";
  23.         }
  24.     }
  25.  
  26.     // Check to see there is an active session
  27.     if( !empty( $_SESSION["username"] ) ){
  28.         echo "You are currently logged in";
  29.     }
  30. ?>
  31. <html>
  32.  
  33. <body>
  34.  
  35. <!-- This form will submit to the same page its on which will trigger the php script above -->
  36. <form action="" method="post">
  37. <label>Username</label>
  38. <input type="text" name="username" />
  39. <label>Password</label>
  40. <input type="text" name="password" />
  41. <input type="submit" value="Login" />
  42. </form>
  43.  
  44. </body>
  45. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement