php使用cookie保存登錄用戶名的方法
更新時(shí)間:2015年01月26日 09:47:48 投稿:shichen2014
這篇文章主要介紹了php使用cookie保存登錄用戶名的方法,包括提交頁面及設(shè)置cookie的方法,需要的朋友可以參考下
本文實(shí)例講述了php使用cookie保存登錄用戶名的方法。分享給大家供大家參考。具體如下:
提交表單頁面
復(fù)制代碼 代碼如下:
<?php
$user = isset($_COOKIE['username'])?$_COOKIE['username']:'';
?>
<form action="file.php" method="post">
用戶名:<input type="text" name="username" value="<?php echo $user; ?>" /><br />
密碼:<input type="password" name="pwd" /><br />
記住用戶名:<input type="checkbox" name="rem" value="1"><br />
<input type="submit" name="sub" value="提交">
</form>
$user = isset($_COOKIE['username'])?$_COOKIE['username']:'';
?>
<form action="file.php" method="post">
用戶名:<input type="text" name="username" value="<?php echo $user; ?>" /><br />
密碼:<input type="password" name="pwd" /><br />
記住用戶名:<input type="checkbox" name="rem" value="1"><br />
<input type="submit" name="sub" value="提交">
</form>
表單信息接收頁面,同時(shí)設(shè)置cookie
復(fù)制代碼 代碼如下:
<?php
$user = $_POST['username'];
if($_POST['rem']){
setcookie("username",$user,time()+3600*3600*24);
}else{
setcookie("username",'',time()-1);
}
echo "登錄成功";
?>
$user = $_POST['username'];
if($_POST['rem']){
setcookie("username",$user,time()+3600*3600*24);
}else{
setcookie("username",'',time()-1);
}
echo "登錄成功";
?>
希望本文所述對大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
PHP+JavaScript實(shí)現(xiàn)無刷新上傳圖片
本文主要介紹了PHP+JavaScript實(shí)現(xiàn)無刷新上傳圖片的方法,具有很好的參考價(jià)值,下面跟著小編一起來看下吧2017-02-02php實(shí)現(xiàn)excel中rank函數(shù)功能的方法
這篇文章主要介紹了php實(shí)現(xiàn)excel中rank函數(shù)功能的方法,較為詳細(xì)的分析了rank函數(shù)的功能及具體實(shí)現(xiàn)方法,需要的朋友可以參考下2015-01-01PHP文件運(yùn)行步驟以及數(shù)據(jù)庫的連接代碼
PHP經(jīng)常搭配MySQL來使用,那么PHP怎樣連接MySQL數(shù)據(jù)庫呢?這篇文章主要給大家介紹了關(guān)于PHP文件運(yùn)行步驟以及數(shù)據(jù)庫連接的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-11-11