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:
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.
Site is a question game. Starts on index.php. Then goes to 1.php, then 2.php, etc, until reaching the end of the questions. Some users don’t finish the question game in one sitting, so they bookmark page and come back later (to index.php). I then need to display different site information allowing user to continue.