欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP记住用户的登录状态cookie

程序员文章站 2024-01-01 17:46:28
...
代码
<?
//读取COOKIE的用户名和密码的值即可
if($_COOKIE['uname']!=''){$CKUNAME =  $_COOKIE['uname'];}
if($_COOKIE['pwd']!=''){$CKPWD =  $_COOKIE['pwd'];}
echo $CKUNAME;
echo '<br>';
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!=''){?>
       checked="checked" <? } ?> /> 记住我! <input type="submit" name="button"
       id="button" value="登录" />
</form>
<?
//登录,将用户名和密码存入到COOKIE
if($_POST['button']!=''){
    $uname = $_POST['uname'];
    $pwd = $_POST['pwd'];
    //如果输入的加密密码和COOKIE中不一样,那么就加密
    if($pwd!=$CKPWD){$pwd = md5($pwd);}
    $remember = $_POST['remember'];
    if($remember==1){
       setcookie("uname", $uname, time()+3600*24*30);
       setcookie("pwd", $pwd, time()+3600*24*30);
    }
}
?>

上一篇:

下一篇: