php利用cookie實(shí)現(xiàn)自動(dòng)登錄的方法
本文實(shí)例講述了php利用cookie實(shí)現(xiàn)自動(dòng)登錄的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
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代碼如下:
$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 "<hl><center>invalid password!!!</center></hl>";
}
}
}
?>
希望本文所述對(duì)大家的PHP程序設(shè)計(jì)有所幫助。
- 利用php實(shí)現(xiàn)一周之內(nèi)自動(dòng)登錄存儲(chǔ)機(jī)制(cookie、session、localStorage)
- php中實(shí)現(xiàn)記住密碼下次自動(dòng)登錄的例子
- php中實(shí)現(xiàn)記住密碼自動(dòng)登錄的代碼
- phpMyAdmin自動(dòng)登錄和取消自動(dòng)登錄的配置方法
- php版微信自動(dòng)登錄并獲取昵稱的方法
- PHP登錄驗(yàn)證功能示例【用戶名、密碼、驗(yàn)證碼、數(shù)據(jù)庫、已登陸驗(yàn)證、自動(dòng)登錄和注銷登錄等】
- PHP基于cookie與session統(tǒng)計(jì)網(wǎng)站訪問量并輸出顯示的方法
- php頁面跳轉(zhuǎn)session cookie丟失導(dǎo)致不能登錄等問題的解決方法
- PHP中cookie和session的區(qū)別實(shí)例分析
- PHP根據(jù)session與cookie用戶登錄狀態(tài)操作類的代碼
- php同時(shí)使用session和cookie來保存用戶登錄信息的實(shí)現(xiàn)代碼
- PHP cookie,session的使用與用戶自動(dòng)登錄功能實(shí)現(xiàn)方法分析
相關(guān)文章
PHP二維索引數(shù)組的遍歷實(shí)例分析【2種方式】
這篇文章主要介紹了PHP二維索引數(shù)組的遍歷,結(jié)合實(shí)例形式分析了php使用for循環(huán)與foreach循環(huán)2種方式遍歷數(shù)組的相關(guān)操作技巧,需要的朋友可以參考下2019-06-06
讓Nginx支持ThinkPHP的URL重寫和PATHINFO的方法分享
ThinkPHP支持通過PATHINFO和URL rewrite的方式來提供友好的URL,只需要在配置文件中設(shè)置 'URL_MODEL' => 2 即可。在Apache下只需要開啟mod_rewrite模塊就可以正常訪問了,但是Nginx中默認(rèn)是不支持PATHINFO的,所以我們需要修改nginx.conf文件。2011-08-08
PHP計(jì)算當(dāng)前坐標(biāo)3公里內(nèi)4個(gè)角落的最大最小經(jīng)緯度實(shí)例
這篇文章主要介紹了PHP計(jì)算當(dāng)前坐標(biāo)3公里內(nèi)4個(gè)角落的最大最小經(jīng)緯度的方法,涉及PHP數(shù)學(xué)運(yùn)算的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-02-02
基于PHP實(shí)現(xiàn)數(shù)據(jù)分頁顯示功能
這篇文章主要為大家詳細(xì)介紹了基于PHP實(shí)現(xiàn)數(shù)據(jù)分頁顯示功能,分頁在后臺(tái)管理中是經(jīng)常使用的功能,分頁顯示方便大量數(shù)據(jù)的管理,感興趣的小伙伴們可以參考一下2016-05-05
PHP 預(yù)定義變量、魔術(shù)常量和魔術(shù)方法功能與用法小結(jié)
這篇文章主要介紹了PHP 預(yù)定義變量、魔術(shù)常量和魔術(shù)方法,總結(jié)分析了PHP 預(yù)定義變量、魔術(shù)常量和魔術(shù)方法基本概念、原理、功能、用法及操作注意事項(xiàng),需要的朋友可以參考下2020-04-04
PHP使用函數(shù)靜態(tài)變量實(shí)現(xiàn)指定迭代次數(shù)的方法
這篇文章主要介紹了PHP使用函數(shù)靜態(tài)變量實(shí)現(xiàn)指定迭代次數(shù)的方法,結(jié)合實(shí)例形式分析了php靜態(tài)變量數(shù)據(jù)存儲(chǔ)的相關(guān)操作技巧,需要的朋友可以參考下2018-03-03
PHP基于cookie實(shí)現(xiàn)統(tǒng)計(jì)在線人數(shù)功能示例
這篇文章主要介紹了PHP基于cookie實(shí)現(xiàn)統(tǒng)計(jì)在線人數(shù)功能,涉及php文件讀寫、cookie訪問、計(jì)算等相關(guān)操作技巧,需要的朋友可以參考下2019-01-01

