I\'m trying to access a cookie\'s value (using $_COOKIE
) immediately after calling the setcookie()
function in PHP. When I do so, $_COOKIE[\
Your script's setcookie()
function runs when the web browser requests the page for the first time, in your case the reload. This cookie is stored in the users browser and isn't available to your script running on the server until the next request, or in your case the next reload.
Upon the next request the browser sends that cookie to the server and the array $_COOKIE
will have the value that you initially set and the browser sent back upon the second request.