cookie保存登录信息 登录成功后setcookie是有值 关闭浏览器在进首页就读取不到值 求解
登录时cookie保存
<br /> if(empty($c)){<br /> echo "不存在的用户名或者密码错误!";exit;<br /> }else{<br /> if(isset($_POST['checked']) && $_POST['checked']!=0){<br /> setcookie('username',$c['username'],time()+60*60*24*7);<br /> setcookie('id',$c['id'],time()+60*60*24*7);<br /> }<br /> //判断是否是ajax请求<br /> if(isset($action)){<br /> echo "登陆成功";<br /> $_SESSION['user']=$c['username'];<br /> }else{<br /> $_SESSION['user']=$c['username'];<br /> header("Location:/");<br /> }<br /> } <br />
<br /> public function index()<br /> {<br /> session_start();<br /> print_r($_COOKIE);<br /> if(isset($_COOKIE['id']) && isset($_COOKIE['username'])){<br /> echo $_COOKIE['username'];exit;<br /> $_SESSION['user']=$_COOKIE['username'];<br /> }<br /> $this->display();<br /> }<br />
<br /> 你看看这里是否执行。<br /> if(isset($_POST['checked']) && $_POST['checked']!=0){<br /> setcookie('username','ssssss',time()+60*60*24*7);<br /> setcookie('id','40',time()+60*60*24*7);<br /> }<br />