PHP » Predefined Variables » Cookie variables

Syntax:
$_COOKIE

This is an associative array containing all the cookies passed from the browser in the last request.

Examples

Code:
<?php

session_start();
@print "Setting cookie #" . ++$_SESSION["j"] . "<br>";
setcookie("testcookie", "cookie " . $_SESSION["j"]);
if (isset($_COOKIE["testcookie"])) {
   print "Testcookie received: " . $_COOKIE["testcookie"];
}

?>
Output:
Setting cookie #7
Testcookie received: cookie 6
Explanation:

Reload the page several time to see how it works. When a cookie is updated, the value will not be available until the next request. For more information about set_cookie(), see the section about Cookies and Sessions.

See Also: