Php uses cookies for automatic logon.
This example describes how php uses cookies to Enable Automatic Logon. Share it with you for your reference. The specific implementation method is as follows:
The html front-end Page code is as follows:
Copy codeThe Code is as follows: <Head>
<Title> enter password </title>
</Head>
<Body>
<Form name = "forml" method = "post" action = "cookiebasedpasswordlogin. php">
<Table>
<Tr>
<Td colspan = "2">
<Div align = "center"> <B> please specify the password </B> </div>
</Td>
</Tr>
<Tr>
<Td>
<Div align = "right"> customer id </div>
</Td>
<Td>
<Input type = "text" name = "username">
</Td>
</Tr>
<Tr>
<Td>
<Div align = "right"> password </div>
</Td>
<Td>
<Input type = "password" name = "password">
</Td>
</Tr>
<Tr>
<Td colspan = "2">
<Center>
<Input type = "submit" name = "submit" value = "login">
</Center>
</Td>
</Tr>
</Table>
</Form>
</Body>
</Html>
The backend PHP code is as follows:
Copy codeThe Code is as follows: <? Php
$ Now = getdate ();
$ Storetime = $ now ["weekday"]. "". $ now ["month"]. "". $ now ["year"];
$ Storetime. = "time :";
If ($ now ["hours"] <10 ){
$ 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 "<B> <center> hi". $ data [2]. "! ! </Center> </B> <br> n ";
Echo "<B> <center> last login time:". $ data [0]. "</center> </B> <br> n ";
Echo "<B> <center> current date:". $ storetime. "</center> </B> <br> n ";
Echo "<B> <center> page view count:". $ data [l]. "</center> </B> <br> n ";
Echo "<B> <center> you have successfully logged in! </Center> </B> ";
Echo ("<B> <contor> you can access this area without entering a password for the next 24 hours! </Center> </B> ");
} 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 "}
}
}
?>
I hope this article will help you with PHP programming.