Guest User

Untitled

a guest
Aug 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. //log out if ?logout=true
  5. if($_GET["logout"]){
  6. $_SESSION["loggedIn"]=false;
  7. header('Location: '. $_SERVER['SCRIPT_NAME']);
  8. }
  9.  
  10. //sha-256 hash of password
  11. $password = '8f434346648f6b96df89dda901c5176b10a6d83961dd3c1ac88b59b2dc327aa4';
  12.  
  13. if(empty($_SESSION["loggedIn"])){
  14. if(isset($_POST["password"])){
  15. if(hash('sha256', $_POST['password'])==$password){
  16. $_SESSION["loggedIn"]=true;
  17. } else{
  18. echo "Incorrect password! <br>";
  19. }
  20. }
  21. }
  22.  
  23. if($_SESSION["loggedIn"] == true){
  24. print '
  25. You are logged in!<br>
  26. <a href="?logout=true">Logout</a>
  27. <!-- Main HTML page goes here-->
  28. ';
  29. } else{
  30. print ' <h3>Login</h3>
  31. <form action="#" method="post">
  32. Password: <input type="password" name="password"><br>
  33. <input type="submit" value="Login!" />
  34. </form>
  35. ';
  36. }
  37. ?>
  38.  
  39. <?php
  40. session_start();
  41. if($_SESSION["loggedIn"]=false){
  42. header('Location: login.php');
  43. } else {
  44. //stuff goes here
  45. }
Add Comment
Please, Sign In to add comment