Chapter 9. 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. Using a Web scripting language like PHP, you can overcome the statelessness of the Web. You have a few options to choose from, the most popular two being cookies and sessions.

Prior to the existence of cookies, surfing a Web site was a trip without a history. Although your browser tracked the pages you visited, allowing you to use the back button to return to previously visited pages, the server kept 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.

Sessions improve upon cookies, allowing the Web application to store and retrieve far more information than cookies alone can. Both technologies are easy to use with PHP and are worth knowing. In this chapter I'll explain each, using a login system, based upon the existing users database, as my example.



    PHP and MySQL for Dynamic Web Sites. Visual QuickPro Guide
    PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    ISBN: 0321336577
    EAN: 2147483647
    Year: 2005
    Pages: 166
    Authors: Larry Ullman

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net