12. Cookies and Sessions

The Hypertext Transfer Protocol (HTTP) is a stateless technology, meaning that each HTML page is an unrelated entity. HTTP has no method for tracking users or retaining variables as a person traverses a site. Without the server being able to track a user, there can be no shopping carts or custom website 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.

The key difference between cookies and sessions is that cookies store data in the user’s browser and sessions store ...

Get PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide, Fifth Edition 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.