Heim  >  Artikel  >  Backend-Entwicklung  >  php 验证登陆cookie出现的一个很奇怪的有关问题,也许大家都没注意。求指导!

php 验证登陆cookie出现的一个很奇怪的有关问题,也许大家都没注意。求指导!

WBOY
WBOYOriginal
2016-06-13 10:21:35818Durchsuche

php 验证登陆cookie出现的一个很奇怪的问题,也许大家都没注意。求指导!!!
大家好, 最近在做一个php网站 废话不多说 直接代码:
登陆成功添加cookie:
setcookie("user",$Email,time()+24*60*60);

header("location:http://website.com/MyProfile.php");

进入页面验证cookie:
if (isset($_COOKIE["user"]))
//echo $_COOKIE['user'];
{

点击退出,删除cookie:
setcookie("user","",time()-24*60*60);
("location:http://website.com/index.php");

问题是这样的:
第一次登陆可以正常登录,进去以后点击退出(清除cookie)。然后再登陆,MyProfile页面就读不到cookie(确定密码正确)。第二次就可以正常登陆。 我已经测试过,设置和删除都没问题,是不是哪一点我没有注意到? 也许是header函数的问题?
求解答

------解决方案--------------------
header和setcookie没有冲突。
是在这两个操作前不能有其他输出。
建议对比代码检查。
------解决方案--------------------
建议换下其它的浏览器,测试前更新下缓存
------解决方案--------------------
是这样子的,
cookie 是要在新一页才生效的。
------解决方案--------------------
你设置的是第二次登录以后才会生效
------解决方案--------------------
第一次登录以后 楼上写错了
------解决方案--------------------
换过其他浏览器测试了吗?

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn