Guest User

Untitled

a guest
Jun 4th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. <?php
  2. // Includes the db and form info.
  3. if ($_SESSION['logged'] == 1) { // User is already logged in.
  4. echo "Already logged in!";
  5. }
  6. else {
  7. if (!isset($_POST['submit'])) { // The form has not been submitted.
  8. echo '
  9. <form method="POST" action="index.php">
  10. <input type="text" class ="text-inp" value="Username" onFocus=this.value="" name="username" ><br />
  11. <input type="password" class ="text-inp" value="Password" onFocus=this.value="" name="password">
  12. <input type="image" src="./images/header/button_input_bg.gif" class ="button" value="Login" name="submit">
  13. </form>
  14. ';
  15. }
  16.  
  17. else {
  18. $username = form($_POST['username']);
  19. $password = md5($_POST['password']); // Encrypts the password.
  20.  
  21. $q = mysql_query("SELECT * FROM `users` WHERE username = '$username' AND password = '$password'") or die (mysql_error()); // mySQL query
  22. $r = mysql_num_rows($q); // Checks to see if anything is in the db.
  23.  
  24. if ($r == 1) { // There is something in the db. The username/password match up.
  25. $_SESSION['logged'] = 1; // Sets the session.
  26. echo '<META HTTP-EQUIV="refresh" CONTENT="1">';
  27. } else { // Invalid username/password.
  28. echo "Incorrect username/password!"; // Stops the script with an error message.
  29. }
  30. }
  31. }
  32. mysql_close($db_connect); // Closes the connection.
  33. ?>
Add Comment
Please, Sign In to add comment