PHP uses cookies to automate the login process, and the cookie automatically logs in
The example in this paper describes how PHP uses cookies for automatic login. Share to everyone for your reference. The implementation method is as follows:
The
HTML front-end page code is as follows:
Copy the code code as follows:
Enter password
copy Code code is as follows: <?php
$now = getdate ();
$storetime = $now ["Weekday"]. " " . $now ["Month"]. " " . $now ["Year"];
$storetime. = "Time:";
if ($now ["hours"] <) {
$storetime. = "0". $now ["hours"];
} else {
$storetime. = $now ["hours"];
}
$storetime. = ":";
if ($now ["Minutes"]<10) {
$storetime. = "0". $now ["Minutes"];
} else {
$storetime. = $now ["Minutes"];
}
$storetime. = ":";
if ($now ["seconds"] <10) {
$storetime. = "0". $now ["seconds"];
} else {
$storetime. = $now ["Seconds"];
}
if (Isset ($data)) {
$counter =++ $data [l];
Setcookie ("data[0]", $storetime, Time () + (60*60*24));
Setcookie ("data[l]", $counter, Time () + (60*60*24)), Setcookie ("data[2", $username, Time () + (60*60*24));
Echo
Hi ". $data [2]. " ! !
n ";
echo "
Last Login time: ". $data [0]."
n ";
echo "
Current date: ". $storetime."
n ";
echo "
Page view count: ". $data [L]. "
n ";
echo "
You have successfully logged in! ";
Echo ("
You can access this area without entering a password for the next hours! ");
} else {
if (Isset ($username) && isset ($password)) {
if ($password = = "SuperPass") {
$counter = 0;
Setcookie ("data[0]", $storetime, Time () + (60*60*24));
Setcookie ("data[l]", $counter, Time () + (60*60*24));
Setcookie ("data[2]", $username, Time () + (60*60*24));
$url = "location:cookieimp.php";
Header ($url);
}else{
echo " Invalid password!!! ";
}
}
}
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/925134.html www.bkjia.com true http://www.bkjia.com/PHPjc/925134.html techarticle PHP uses cookies to implement the automatic login method, the cookie automatically log in this article describes the PHP use of cookies for automatic login method. Share to everyone for your reference. Concrete implementation methods such as ...