本文实例讲述了php利用cookie实现自动登录的方法。分享给大家供大家参考。具体实现方法如下:
html前端页面代码如下:
复制代码 代码如下:<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>
后端PHP代码如下:
复制代码 代码如下:<"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 "<hl><center>invalid password!!!</center></hl>";
}
}
}
?>
希望本文所述对大家的PHP程序设计有所帮助。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 柏菲·珞叔作品集《金色大厅2》限量开盘母带ORMCD[低速原抓WAV+CUE]
- Gareth.T《sad songs(Explicit)》[320K/MP3][29.03MB]
- Gareth.T《sad songs(Explicit)》[FLAC/分轨][152.85MB]
- 证声音乐图书馆《海风摇曳·盛夏爵士曲》[320K/MP3][63.06MB]
- 龚玥《金装龚玥HQCD》头版限量[WAV分轨]
- 李小春《吻别》萨克斯演奏经典[原抓WAV+CUE]
- 齐秦《辉煌30年24K珍藏版》2CD[WAV+CUE]
- 证声音乐图书馆《海风摇曳·盛夏爵士曲》[FLAC/分轨][321.47MB]
- 群星 《世界经典汽车音乐》 [WAV分轨][1G]
- 冷漠.2011 《冷漠的爱DSD》[WAV+CUE][1.2G]
- 陈明《流金岁月精逊【中唱】【WAV+CUE】
- 群星《Jazz-Ladies1-2爵士女伶1-2》HQCD/2CD[原抓WAV+CUE]
- 群星《美女私房歌》(黑胶)[WAV分轨]
- 郑源.2009《试音天碟》24BIT-96KHZ[WAV+CUE][1.2G]
- 飞利浦试音碟 《环球群星监听录》SACD香港版[WAV+CUE][1.1G]