Session Management with Cookies

Now that you’ve seen how to create cookies and how to retrieve them after they’ve been stored, I can show you how to create and maintain sessions using cookies. You’re going to create what in all likelihood is the world’s smallest shopping site, because the catalog only contains two items. The way the site works is that there is a separate cookie for each unique item in the catalog. The cookie stores the quantity of the item that the user is going to order. When the user checks out of the store, the check-out program looks at the cookies that are sent back by the browser and builds a list of items that the user has ordered.

This isn’t how a real shopping site would work; if there were thousands of items in the ...

Get Sams Teach Yourself CGI in 24 Hours, Second 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.