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 "}
}
}
?>