Changes

Jump to: navigation, search

PHP and Cookies - Creating, Reading and Writing

7 bytes added, 14:42, 6 June 2007
Reading a Cookie
The above example creates a cookie on the computer system of anyone who loads the page (assuming they have cookies enabled in their browser) containing the name value pair ''userName=JohnW'. The cookie will expire 4800 seconds from the time it is created.
== Reading a Cookie in PHP ==
Gven that you've gone to the trouble of writing a cookie it stands to reason you'll probably want to read it back at some point. This is achieved by accessing the $_COOKIE array. The $_COOKIE array is an associative array whereby the name of the cookie provides the index into the array to extract the corresponding value of the name/value pair (for details of PHP arrays read the [[PHP Arrays]] chapter of this book.

Navigation menu