Php automatic login using cookies

Source: Internet
Author: User

Php tutorial how to use cookies for Automatic Login

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




<! -- Cookiebasedpasswordlogin. php
<? 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 "}
}
}
?>


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.