On my website I'm trying to echo a string if a cookie has been set on another page. However it only checks if the cookie isset after I've refreshed the page. Here is my code:
question/5.php (this part works fine)
if(isset($_COOKIE['intoGame'])){
}
else{
$intoGameGet = "into";
setcookie('intoGame', $intoGameGet, time() + (86400 * 14), '/');
}
This cookie is set on the 5.php page. Then on index php I try to access the cookie. This is where the problem happens.
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"];
}
Then lower on the page I echo out $content1. If the cookie has been set, it should echo 'hello question 5 answered'. However it does not do this unless I refresh the page.
In simple terms: I set the cookie on (page1). Then on (page2) I try to access the cookies previously set. However I need to refresh the page on (page2) before I see the cookie.
Any help would be appreciated.