Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. $userinfo = array(
  5. 'user1'=>'password1',
  6. 'user2'=>'password2'
  7. );
  8.  
  9. if(isset($_GET['logout'])) {
  10. $_SESSION['username'] = '';
  11. header('Location: ' . $_SERVER['PHP_SELF']);
  12. }
  13.  
  14. if(isset($_POST['username'])) {
  15. if($userinfo[$_POST['username']] == $_POST['password']) {
  16. $_SESSION['username'] = $_POST['username'];
  17. }else {
  18. //Invalid Login
  19. }
  20. }
  21. ?>
  22. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  23. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head>
  26. <title>Login</title>
  27. </head>
  28. <body>
  29. <?php if($_SESSION['username']): ?>
  30. <p>You are logged in as <?=$_SESSION['username']?></p>
  31. <p><a href="?logout=1">Logout</a></p>
  32. <?php endif; ?>
  33. <form name="login" action="" method="post">
  34. Username: <input type="text" name="username" value="" /><br />
  35. Password: <input type="password" name="password" value="" /><br />
  36. <input type="submit" name="submit" value="Submit" />
  37. </form>
  38. </body>
  39. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement