Guest User

Untitled

a guest
Aug 16th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $userArray = array(
  4. "username1" => "password1",
  5. "username2" => "password2",
  6. "username3" => "password3"
  7. );
  8.  
  9. if (isset($_SESSION['user']))
  10. {
  11. $logout=true;
  12. foreach($userArray as $username)
  13. {
  14. if ($username == $_SESSION['user'])
  15. $logout=false;
  16. }
  17. if (isset($_GET['logout'])||$logout=true;)
  18. {
  19. session_destroy();
  20. header("Location: ./");
  21. }
  22.  
  23. //logged in stuff goes here
  24. }
  25. else
  26. {
  27. if (isset($_POST['username']))
  28. {
  29. $username = $_POST['username'];
  30. $password = $_POST['password'];
  31.  
  32. if ($userArray[$username] == $password)
  33. {
  34. $_SESSION['user'] = $username;
  35. header("Location: ./");
  36. }
  37. else
  38. {
  39. //fail
  40. }
  41. }
  42.  
  43. ?>
  44. <form method="post">
  45. Username: <input name="username" /><br/>
  46. Password: <input name="password" /><br/>
  47. <input type="submit" value="Login" />
  48. </form>
  49. <?php
  50. }
  51. ?>
Add Comment
Please, Sign In to add comment