A McGraw Hill Book Plug-in PHP: 100 Power Solutions
By Robin Nixon (McGraw Hill 2010, ISBN 978-0071666596)

Home | About | Buy It | Download | Contact

Select Chapter: 1  2  3  4  5  6  7  8  9 10 11 12

Chapter 9: Plug-in 69 - Manage Cookie

Cookies are a great way to provide additional functionality to your users and, contrary to the impression that some news reports might give, are not only to track them for advertising purposes. For example, you can save a person's user name and password in a cookie to keep them logged into a site, something PHP sessions do unless cookies are disabled. Cookies are also great for associating variables directly with a user via the browser they use, so you could use them, for example, to make a note that a user has already completed a questionnaire on your site and should not be asked again.

The Figure shows the cookie Test being given the value 3.1415927 by this plug-in. The cookie is sent to the browser but has not been returned by it because cookies are only transferred in the header exchange that takes place before the contents of a web page is transferred. After reloading the page the cookie is passed back to the web server by the browser and so the cookie returns the assigned value, as the Figure inset shows.