php基于cookie的登录表单(记录最后登录时间)
程序员文章站
2022-05-23 23:27:43
...
本文介绍下,基于cookie实现的一个php登录表单,且可以记录下最后的登录时间,有需要的朋友参考下。 一个基于cookie原理实现的登录表单。 代码: <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>"; } } } ?> --> |
|