首頁 >php教程 >PHP源码 >PHP记住用户的登录状态cookie

PHP记住用户的登录状态cookie

PHP中文网
PHP中文网原創
2016-05-25 17:09:441574瀏覽

代码

<?
//读取COOKIE的用户名和密码的值即可
if($_COOKIE[&#39;uname&#39;]!=&#39;&#39;){$CKUNAME =  $_COOKIE[&#39;uname&#39;];}
if($_COOKIE[&#39;pwd&#39;]!=&#39;&#39;){$CKPWD =  $_COOKIE[&#39;pwd&#39;];}
echo $CKUNAME;
echo &#39;<br>&#39;;
echo $CKPWD;
?>
<form id="form1" name="form1" method="post" action="">
    <input type="text" name="uname" id="uname" value="<?=$CKUNAME;?>" /> <input
       type="password" name="pwd" id="pwd" value="<?=$CKPWD;?>" /> <input
       name="remember" type="checkbox" value="1" <? if($CKUNAME!=&#39;&#39;){?>
       checked="checked" <? } ?> /> 记住我! <input type="submit" name="button"
       id="button" value="登录" />
</form>
<?
//登录,将用户名和密码存入到COOKIE
if($_POST[&#39;button&#39;]!=&#39;&#39;){
    $uname = $_POST[&#39;uname&#39;];
    $pwd = $_POST[&#39;pwd&#39;];
    //如果输入的加密密码和COOKIE中不一样,那么就加密
    if($pwd!=$CKPWD){$pwd = md5($pwd);}
    $remember = $_POST[&#39;remember&#39;];
    if($remember==1){
       setcookie("uname", $uname, time()+3600*24*30);
       setcookie("pwd", $pwd, time()+3600*24*30);
    }
}
?>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn