php利用cookie實(shí)現(xiàn)自動(dòng)登錄的方法
本文實(shí)例講述了php利用cookie實(shí)現(xiàn)自動(dòng)登錄的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
html前端頁(yè)面代碼如下:
<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)登錄并獲取昵稱(chēng)的方法
- PHP登錄驗(yàn)證功能示例【用戶(hù)名、密碼、驗(yàn)證碼、數(shù)據(jù)庫(kù)、已登陸驗(yàn)證、自動(dòng)登錄和注銷(xiāo)登錄等】
- PHP基于cookie與session統(tǒng)計(jì)網(wǎng)站訪問(wèn)量并輸出顯示的方法
- php頁(yè)面跳轉(zhuǎn)session cookie丟失導(dǎo)致不能登錄等問(wèn)題的解決方法
- PHP中cookie和session的區(qū)別實(shí)例分析
- PHP根據(jù)session與cookie用戶(hù)登錄狀態(tài)操作類(lèi)的代碼
- php同時(shí)使用session和cookie來(lái)保存用戶(hù)登錄信息的實(shí)現(xiàn)代碼
- PHP cookie,session的使用與用戶(hù)自動(dòng)登錄功能實(shí)現(xiàn)方法分析
相關(guān)文章
PHP高精確度運(yùn)算BC函數(shù)庫(kù)實(shí)例詳解
這篇文章主要介紹了PHP高精確度運(yùn)算BC函數(shù)庫(kù),結(jié)合實(shí)例形式分析了BC函數(shù)庫(kù)中bccomp、bcadd、bcsub、bcmod、bcdiv、bcmul等函數(shù)的功能以及高精度數(shù)學(xué)運(yùn)算使用方法,需要的朋友可以參考下2017-08-08淺析HTTP消息頭網(wǎng)頁(yè)緩存控制以及header常用指令介紹
本篇文章是對(duì)HTTP消息頭網(wǎng)頁(yè)緩存控制以及header常用指令進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06PHP 抽象方法與抽象類(lèi)abstract關(guān)鍵字介紹及應(yīng)用
抽象方法指沒(méi)有方法體的方法,只要一個(gè)類(lèi)里面有一個(gè)方法是抽象方法,那么這個(gè)類(lèi)就要定義為抽象類(lèi),不了解的朋友可以看看2014-10-10PHP 雜談《重構(gòu)-改善既有代碼的設(shè)計(jì)》之三 重新組織數(shù)據(jù)
承接上文的PHP 雜談《重構(gòu)-改善既有代碼的設(shè)計(jì)》之 重新組織你的函數(shù)繼續(xù)重構(gòu)方面的內(nèi)容2012-04-04