开发者

Does _COOKIE info have only the cookies of the current Request

What does _COOKIE variable contain. Does it just contain the cookie that is sent b开发者_如何学Cy the browser for the current request?


That is correct!

$_COOKIE

The value of $_COOKIE is determined by the content of cookies received in the user agent's request.


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.


Pretty much on the dot...

You basically use $_COOKIE to get the data stored in cookies from the browser

Of course cookies are not always very reliable, as they can be turned off by the client but nonetheless used widely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜