溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么在php中使用cookie實(shí)現(xiàn)一個(gè)記住密碼功能

發(fā)布時(shí)間:2020-12-24 15:43:54 來(lái)源:億速云 閱讀:171 作者:Leah 欄目:開發(fā)技術(shù)

怎么在php中使用cookie實(shí)現(xiàn)一個(gè)記住密碼功能?相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form id="form1" name="form1" method="post" action="check_remember.php">
<table width="300" border="1" align="center" cellpadding="0" cellspacing="0">
<thead>
 <tr> 
 <td colspan="2" align="center"><b>記住用戶名和密碼</b></td> 
 </tr>
</thead> 
 <tr align="center">
 <td>用 戶 名:</td>
 <td><input type="text" value="<?php echo $_COOKIE['name'];?>" name="name"></td>
 </tr>
 <tr align="center">
 <td>密碼:</td>
 <td><input type="password" name="password" value="<?php echo $_COOKIE['password']?>"></td>
 </tr>
 <tr align="center">
 <td>記住用戶名和密碼</td>
 <td><?php if($_COOKIE['remember'] == 1){?><input type="checkbox" name="remember" value="1" checked><?php }else{($_COOKIE['remember'] == "")?><input type="checkbox" name="remember" value="1"><?php }?></td>
 </tr>
 <tr align="center">
 <td colspan="2"><input type="submit" name="Submit" value="提交" /></td>
 </tr>
</table>
</form>
 
check_remember.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
 $name = $_POST['name'];
 $password = $_POST['password'];
 $remember = $_POST['remember'];
 if($remember == 1){
 setcookie('name',$name,time()+3600);
 setcookie('password',$password,time()+3600);
 setcookie('remember',$remember,time()+3600);
 }else{
 setcookie('name',$name,time()-3600);
 setcookie('password',$password,time()-3600);
 setcookie('remember',$remember,time()-3600);
 }
 echo "<a href=\"remember.php\">返回</a>";
?>

看完上述內(nèi)容,你們掌握怎么在php中使用cookie實(shí)現(xiàn)一個(gè)記住密碼功能的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI