Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <?php
  2. session_start();
  3. // dBase file
  4. include "dbConfig.php";
  5.  
  6. if ($_GET["op"] == "login")
  7. {
  8. if (!$_POST["username"] || !$_POST["password"])
  9. {
  10. die ("You need to provide a username and password.");
  11. }
  12.  
  13. // Create query
  14. $q = "SELECT * FROM `dbUsers` "
  15. ."WHERE `username`='".$_POST["username"]."' "
  16. ."AND `password`=PASSWORD('".$_POST["password"]."') "
  17. ."LIMIT 1";
  18. // Run query
  19. $r = mysql_query($q);
  20.  
  21. if ( $obj = @mysql_fetch_object($r) )
  22. {
  23. // <strong class="highlight">Login</strong> good, create session variables
  24. $_SESSION["valid_id"] = $obj->id;
  25. $_SESSION["valid_user"] = $_POST["username"];
  26. $_SESSION["valid_time"] = time();
  27.  
  28. // Redirect to member page
  29. Header("Location: members.php");
  30. }
  31. else
  32. {
  33. // <strong class="highlight">Login</strong> not successful
  34. die("Sorry, could not log you in. Wrong <strong class="highlight">login</strong> information.");
  35. }
  36. }
  37. else
  38. {
  39. //If all went right the Web form appears and users can log in
  40. echo "<form action=\"?op=login\" method=\"POST\">";
  41. echo "Username: <input name=\"username\" size=\"15\"><br />";
  42. echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
  43. echo "<input type=\"submit\" value=\"Login\">";
  44. echo "</form>";
  45. }
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement