php使用cookie實現(xiàn)記住用戶名和密碼實現(xiàn)代碼
更新時間:2015年04月27日 10:22:59 投稿:junjie
這篇文章主要介紹了php使用cookie實現(xiàn)記住用戶名和密碼實現(xiàn)代碼,本文直接給出實現(xiàn)代碼,需要的朋友可以參考下
<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>";
?>
您可能感興趣的文章:
- 詳解PHP中cookie和session的區(qū)別及cookie和session用法小結(jié)
- thinkphp3.x中cookie方法的用法分析
- php通過curl添加cookie偽造登陸抓取數(shù)據(jù)的方法
- PHP基于cookie與session統(tǒng)計網(wǎng)站訪問量并輸出顯示的方法
- php使用CURL不依賴COOKIEJAR獲取COOKIE的方法
- php使用cookie實現(xiàn)記住登錄狀態(tài)
- php實現(xiàn)cookie加密的方法
- php使用cookie保存用戶登錄的用戶名實例
- php使用cookie顯示用戶上次訪問網(wǎng)站日期的方法
- PHP利用Cookie設(shè)置用戶30分鐘未操作自動退出功能
相關(guān)文章
PHP的Laravel框架中使用消息隊列queue及異步隊列的方法
這篇文章主要介紹了PHP的Laravel框架中使用消息隊列queue及異步隊列的方法,針對Laravel 5.0后的版本,示例環(huán)境為Linux系統(tǒng),需要的朋友可以參考下2016-03-03
Zend Framework教程之資源(Resources)用法實例詳解
這篇文章主要介紹了Zend Framework教程之資源(Resources)用法,結(jié)合實例形式詳細分析了Resources的功能,定義,使用方法與相關(guān)注意事項,需要的朋友可以參考下2016-03-03
php getcwd與dirname(__FILE__)區(qū)別詳解
這篇文章主要介紹了php getcwd與dirname(__FILE__)區(qū)別詳解的相關(guān)資料,需要的朋友可以參考下2016-09-09

