即使在单独的页面

时间:2015-08-18 00:37:49

标签: php cookies isset setcookie

在我的网站上,如果在另一个页面上设置了cookie,我会尝试回显字符串。但是,它仅在我刷新页面后检查cookie是否已设置。这是我的代码:

question / 5.php(这部分工作正常)

if(isset($_COOKIE['intoGame'])){
}
else{
$intoGameGet = "into";
setcookie('intoGame', $intoGameGet, time() + (86400 * 14), '/');   
}

此cookie在5.php页面上设置。然后在索引php上我尝试访问cookie。这就是问题发生的地方。

if (!isset($_COOKIE["intoGame"])){  //(only checks this after 1 refresh)
$content1 = 'the cookie has not been set';

}
else{
$content1 = 'hello question 5 answered';
echo $_COOKIE["intoGame"];
}

然后在页面下方我回显$ content1。如果已经设置了cookie,它应该回答“问题5回答”#39;但是,除非我刷新页面,否则它不会这样做。

简单来说:我在(第1页)上设置了cookie。然后在(第2页)我尝试访问先前设置的cookie。但是,在看到cookie之前,我需要刷新页面(第2页)。

任何帮助都将不胜感激。

0 个答案:

没有答案