PHP Automatic login method using cookies, Cookies automatically login _php tutorial

Source: Internet
Author: User

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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.