11 Cookies and Sessions

The Hypertext Transfer Protocol (HTTP) is a stateless technology, meaning that each individual HTML page is an unrelated entity. HTTP has no method for tracking users or retaining variables as a person traverses a site. Although your browser tracks the pages you visit, the server keeps no record of who had seen what. Without the server being able to track a user, there can be no shopping carts or custom Web site personalization. Using a server-side technology like PHP, you can overcome the statelessness of the Web. The two best PHP tools for this purpose are cookies and sessions.

As you probably already know, cookies store data in the user’s Web browser. When the user accesses a page on the site from which the cookie ...

Get PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.