Advertisement
Guest User

Untitled

a guest
Jun 10th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $user["stackoverflow"] = "isawesome";
  4.  
  5. if (!isset($_SESSION['logged_in']))
  6. {
  7. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  8. {
  9. if (empty($_POST['username']) || empty($_POST['password']))
  10. {
  11. exit('<br /><br /><html><body><div id="center"><h2> Login Status: <br/></h2><span style="color:red; font-weight: bold">Please fill in all fields!</span></div><meta http-equiv="refresh" content="1"></body>');
  12. }
  13. elseif ($user[$_POST['username']] != $_POST['password'])
  14. {
  15. exit('<br /><br /><div id="center"><h2> Login Status: <br/></h2><span style="color:red; font-weight: bold">Your username/password is wrong!</span></div><meta http-equiv="refresh" content="1"></body>');
  16. }
  17. else
  18. {
  19. $_SESSION['ingelogd'] = true;
  20. echo '<div id="center"><h2> Login Status: <br/></h2><span style="color:green; font-weight: bold">You are now logged in!</span></div>';
  21. if(!isset($_COOKIE['ingelogd'])){
  22. setcookie("ingelogd", "ingelogd", time() + (10 * 365 * 24 * 60 * 60));
  23. die(header("Location: /index.html"));
  24. }
  25. }
  26. }
  27. else
  28. {
  29. exit('<br /><br />
  30. <link rel="stylesheet" href="/css/body.css">
  31. <link rel="stylesheet" href="/css/button.css">
  32. <div id="center">
  33. <form method="POST" action=""><p>
  34. Username:<br />
  35. <input type="text" name="username" /><br /><br />
  36. Password:<br />
  37. <input type="password" name="password" /><br /><br />
  38. <input type="submit" value="Login" /> <input type="reset" value="Empty fields" />
  39. </form></div>');
  40. }
  41. }
  42. ?>
  43. <link rel="stylesheet" href="/css/body.css">
  44.  
  45. <?php
  46. session_start();
  47. //if user is logged in, "user" toolbox will show
  48. if (isset($_SESSION['ingelogd']) && $_SESSION['ingelogd'] == true) {
  49. echo "<ul id="menu">
  50. <li class="li"><a class="active" href="#home">Home</a></li>
  51. <li class="li"><a id="a" href="html/info/news.html">News</a></li>
  52. <li class="li"><a id="a" href="html/info/contact.html">Contact</a></li>
  53. <li class="li"><a id="a" href="html/info/about.html">About</a></li>
  54. <li class="li"><a id="a" href="html/auth/logout.php" style="float:right">Log out</a></li>
  55. </ul>
  56. <br/>";
  57. }
  58. //if not logged in, this will show
  59. else {
  60. echo "<ul id="menu">
  61. <li class="li"><a class="active" href="#home">Home</a></li>
  62. <li class="li"><a id="a" href="html/info/news.html">News</a></li>
  63. <li class="li"><a id="a" href="html/info/contact.html">Contact</a></li>
  64. <li class="li"><a id="a" href="html/info/about.html">About</a></li>
  65. <li class="li"><a id="a" href="html/auth/login.php" style="float:right">Log in</a></li>
  66. </ul>
  67. <br/>";
  68. }
  69. ?>
  70. <link rel="stylesheet" href="/css/menu.css">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement