Home > Article > Backend Development > PHP cookie-based login form (recording the last login time)
This article introduces a php login form based on cookies, and can record the last login time. Friends in need can refer to it. A login form based on cookie principle. Code: <html> <head> <title>用户登录表单</title> </head> <body> <form name="forml" method="POST" action="CookieBasedPasswordLogin.php"> <table> <tr> <td colspan="2" > <p align="center"><b>请输入用户名与密码</b></p> </td> </tr> <tr>> <td> <p align="right">Customer ID</p> </td> <td> <input type="text" name="username"> </td> </tr> <tr> <td> <p align="right">Password</p> </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 //检测用户登录 //基于cookie实现的用户登录检测程序 //edit by www.jbxue.com $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>成功登录!</center></b>"; echo ("<b><contor>您可以在24小时内,无需再次登录,即可访问本站的内容。</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 "<hl><center>密码无效!</center></hl>"; } } } ?> --> |
|