当前位置:Gxlcms > PHP教程 > 【PHP】基于Cookie的登录和身份认证

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

时间:2021-07-01 10:21:17 帮助过:13人阅读

<无详细内容>
  1. Enter 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. ?>

人气教程排行