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

PHP记住用户的登录状态cookie

PHP中文网
Release: 2016-05-25 17:09:44
Original
1588 people have browsed it

代码

<?
//读取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);
    }
}
?>
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template