Is there any way to get all cookies set in php application (with no request) ? I want to do something like this:
setcookie("cookieName", "test");
print_r($_COOKIE);
Above code of course doesn't work (work only when app is requested by browser)
You can use headers_list()
which will give you an array of headers that are ready to be sent to the client,
headers_list(); //doesn't take any params
eg result:
Array ( [0] => X-Powered-By: PHP/5.5.9-1ubuntu4.9 [1] => Set-Cookie: cookieName=test )
Most of your question can be answered by just visiting the setcookie() php manual.
Cookies cannot be verified until the next page load. You can manually set $_COOKIE['test']
at the time you call setcookie although this value will not be persistent if the user's browser does not store the cookie.
Other than storing the values yourself, you can use headers_list() to return what headers will be, or have been, sent by PHP, but as stated earlier, this will not verify the cookie has actually been set on the user side.