The contents of the superglobal variable $ _COOKIE:
When retrieving cookies with PHP using the superglobal $ _ COOKIE associative array of variables passed to the current script via HTTP cookies.
To check all cookie variables, just use:
print_r($_COOKIE);
To get the value of a specific cookie variable, specify the cookie variable key:
echo $_COOKIE["myVariableName"];
The hardest part about getting cookies with PHP is that the cookie variable will not be available until the request is set. Therefore, you cannot access the cookie with PHP until the following page loads :
// Cannot have output before setting cookies. // Cookie will be sent along w the rest of the HTTP headers. setcookie("name", "Pat"); // If the above was the first time "name" was set, // this will echo NOTHING!!! echo $_COOKIE["name"]; // You will only be able to retrieve $_COOKIE["name"] after the // next page load.
source share