From the manual:
Cookies will not become visible until the next loading of a page that the cookie should be visible for
Meaning that a cookie created with setcookie
will not be accessible in $_COOKIE
until the next page load. Is there a work around for this? Is there a way to detect the cookies created with setcookie
in PHP without a reload?
I can't modify the code near the setcookie
call in the current codebase. So an solution like this won't work:
setcookie('test', 'my test value');
$_COOKIE['test'] = 'my test value';
The _COOKIES superglobal is created as part of the script's initialization, and then is left alone by PHP. As such, any cookies you create later in the script will not magically appear in the array, as they were not present at initialization time.
You can override the built-in setcookie functionality with runkit_function_redefine()
, but if you're not very careful, you can open yourself up to a world of hurt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With