欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

【PHP】基于 Cookie 的登录和身份认证

程序员文章站 2023-12-26 19:17:49
...
  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"] $storetime.= "0" . $now["hours"];
  5. } else {
  6. $storetime.= $now["hours"];
  7. }
  8. $storetime.= ":";
  9. if ($now["minutes"] $storetime.= "0" . $now["minutes"];
  10. } else {
  11. $storetime.= $now["minutes"];
  12. }
  13. $storetime.= ": ";
  14. if ($now["seconds"] $storetime.= "0" . $now["seconds"];
  15. } else {
  16. $storetime.= $now["seconds"];
  17. }
  18. if (isset($data)) {
  19. $counter=++$data[l];
  20. setcookie("data[0]",$storetime,time() + (60*60*24));
  21. setcookie("data[l]", $counter,time() + (60*60*24)); setcookie("data[2]",$username,time() + (60*60*24));
  22. echo "
    Hi " . $data[2] . " ! !

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

    \n";
  24. echo "
    Current Date :" .$storetime. "

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

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

上一篇:

下一篇: