Home  >  Article  >  Backend Development  >  [PHP] Cookie-based login and authentication

[PHP] Cookie-based login and authentication

WBOY
WBOYOriginal
2016-07-25 09:11:25849browse
  1. Enter Password
  2. >
  3. Please Specify the Password
  4. Customer ID
  5. Password
复制代码
  1. $now = getdate();
  2. $storetime= $now["weekday"] . " " . $now["month"] ." " . $now["year"] ;
  3. $storetime.=" Time : ";
  4. if ($now["hours"] < 10) {
  5. $storetime.= "0" . $now["hours"];
  6. } else {
  7. $storetime.= $now["hours"];
  8. }
  9. $storetime.= ":";
  10. if ($now["minutes"]<10) {
  11. $storetime.= "0" . $now["minutes"];
  12. } else {
  13. $storetime.= $now["minutes"];
  14. }
  15. $storetime.= ": ";
  16. if ($now["seconds"] <10) {
  17. $storetime.= "0" . $now["seconds"];
  18. } else {
  19. $storetime.= $now["seconds"];
  20. }
  21. if (isset($data)) {
  22. $counter=++$data[l];
  23. setcookie("data[0]",$storetime,time() + (60*60*24));
  24. setcookie("data[l]", $counter,time() + (60*60*24)); setcookie("data[2]",$username,time() + (60*60*24));
  25. echo "
    Hi " . $data[2] . " ! !

    n";
  26. echo "
    Last Login Time :" .$data[0] . "

    n";
  27. echo "
    Current Date :" .$storetime. "

    n";
  28. echo "
    Page View Count :" . $data[l]. "

    n";
  29. echo "
    You have successfully logged in!
    ";
  30. echo ("You can access this area without entering a password for the next 24 hours!");
  31. } else {
  32. if (isset($username) && isset($password)) {
  33. if ($password=="superpass") {
  34. $counter=0;
  35. setcookie("data[0]",$storetime,time() + (60*60*24));
  36. setcookie("data[l]",$counter,time() + (60*60*24));
  37. setcookie("data[2]",$username,time() + (60*60*24));
  38. $url="Location: cookieimp.php";
  39. header($url);
  40. }else{
  41. echo "
    INVALID PASSWORD!!!
    ";
  42. }
  43. }
  44. }
  45. ?>
复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn