Hi all, What does _COOKIE variable contain. Does it just contain the cookie that is sent by the browser for the current request?
+1
A:
Contents of the $_COOKIE superglobal variable:
When retrieving cookies with PHP using the superglobal $_COOKIE an associative array of variables passed to the current script via HTTP Cookies is returned.
To inspect all the cookie variables simply use:
print_r($_COOKIE);
To retrieve the value of a specific cookie variable, reference the key of the cookie variable:
echo $_COOKIE["myVariableName"];
The trickiest thing about retrieving cookies with PHP is that a cookie variable will not be available until the request after it is set. So you cannot access a cookie with PHP until after the next page load:
// 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.
Peter Ajtai
2010-09-01 01:55:42