Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <?php
  2. $my_username = "comp321";
  3. $my_password = "comp321_0910";
  4. $expire_period = time()+60*60;
  5. $login_success = false;
  6. if(isset($_POST['username'])){
  7. $username = $_POST['username'];
  8. $password = $_POST['password'];
  9. setcookie("login_success", false, $expire_period);
  10. if($username == $my_username && $password == $my_password){
  11. $login_success = true;
  12. setcookie("login_success", true, $expire_period);
  13. setcookie("login_time", date(DATE_COOKIE), $expire_period);
  14. header( "Location:".$_SERVER['PHP_SELF'] );
  15. exit();
  16. }
  17. }
  18. if(isset($_GET['logout'])){
  19. setcookie("login_success", '', time()-3600);
  20. setcookie("login_time", '', time()-3600);
  21. header( "Location:".$_SERVER['PHP_SELF'] );
  22. exit();
  23. }
  24. ?>
  25. <html>
  26. <body>
  27. <?php
  28. if(isset($_COOKIE['login_success'])){
  29. ?>
  30. You are already logged in successfully. <br><br>
  31. Your last login time is <?php echo $_COOKIE['login_time']; ?>.<br><br>
  32. <a href="<?php echo $_SERVER['PHP_SELF']; ?>?logout=1">Logout</a>
  33. <?php
  34. }else{
  35. ?>
  36. <form name="frm_login" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  37. <table width="300" border="0" cellspacing="5" cellpadding="5">
  38. <tr>
  39. <td>Username : </td>
  40. <td><input name="username" id="username" type="text"></td>
  41. </tr>
  42. <tr>
  43. <td>Password : </td>
  44. <td><input name="password" id="password" type="password"></td>
  45. </tr>
  46. <tr>
  47. <td>&nbsp;</td>
  48. <td><input type="submit" value="Login"></td>
  49. </tr>
  50. </table>
  51. </form>
  52. <?php
  53. if($login_success == false && isset($_POST['username'])){
  54. ?>
  55. <font color="#FF0000">
  56. <b>username or password incorrect!</b></font><br><br>
  57. <?php
  58. }
  59. ?>
  60. For testing: <br>
  61. username : <?=$my_username?><br>
  62. password : <?=$my_password?>
  63. <?php
  64. }
  65. ?>
  66. </body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement