Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. PHP FOR SQL RELATED LOGINS.
  2.  
  3. <?php
  4. session_start();
  5. $username = $_POST["username"];
  6. $password=$_POST["password"];
  7. if ($username=="John" && $password=="pass"){
  8. $_SESSION['login']= $username;
  9. header("location: index.php");
  10. }
  11. else{
  12. header("location: login.html");
  13. }
  14. ?>
  15.  
  16. PHP HEADER FOR ANY PAGE THAT REQUIRES A LOGGED IN USER
  17.  
  18. <?php
  19. session_start();
  20. if (!isset($_SESSION['login'])) {
  21. header("location: login.html");
  22. }
  23. else{
  24. print "You've successfully logged in.<br>";
  25. session_destroy( ); // simulation of logout
  26. }
  27. ?>
  28.  
  29. USER LOGIN FORM VALIDATION
  30.  
  31. <?php
  32. session_start();
  33. if(!empty($_POST["username"])) // if username not empty
  34. {
  35. $username = $_POST["username"];
  36. $password = $_POST["password"];
  37. if($username == "user1") { // Simulation of
  38. database login query for $username
  39. if($password == "pass1") { // Simulation
  40. of database login query for $password
  41.  
  42. $_SESSION['login'] = $username;
  43. echo 4; // Success!
  44. }
  45. else echo 3; // username OK but password
  46. incorrect
  47. }
  48. else echo 2; //username incorrect
  49. }
  50. else echo 1; // usernameis blank
  51.  
  52. ?>
  53.  
  54. FOR THE LOGOUT.PHP
  55.  
  56. <?php
  57. session_start();
  58. session_destroy();
  59. echo "You have logged out! If your browser does not redirect you, click the link below!<br><br>";
  60. // sleep for 4 seconds
  61. sleep(4)
  62. header( 'Location: /index.html' );
  63. // Shannon, honestly dunno if that redirect to index works,
  64. // but, whatever its worth a shot for some marks.
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement