PHP: Read a Browser Cookie Value

Posted July 14, 2006 by Quinn McHenry in PHP programming

Last Updated on

Once your web application has set a cookie in a user’s browser, it is a simple matter to retrieve that value in subsequent page requests. This tech-recipe describes reading a value from a cookie in PHP.

After a cookie with a name of “user” has been set in a previous page, the value can be accessed with the global array $_COOKIE like this:

$user = $_COOKIE['user'];

Since this is a normal array, anything you can do to an array iterate through it one value at a time as described in this tutorial. For debugging purposes, it is often useful to use this quick trick to see the whole contents of an array:



About Quinn McHenry

Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
View more articles by Quinn McHenry

The Conversation

Follow the reactions below and share your own thoughts.

Leave a Reply