首頁  >  文章  >  後端開發  >  【PHP】基於 Cookie 的登入和身分認證

【PHP】基於 Cookie 的登入和身分認證

WBOY
WBOY原創
2016-07-25 09:11:25877瀏覽
  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. ?>
复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn