Chapter 13: Cookies and Session Variables


Download CD Content

The goal of this chapter is to describe the use and application of cookies and session variables.

Background

The design of the original World Wide Web was to support sharing of information among scientists using what are termed stateless protocols. The browser program on the client computer sends requests to the server software on the server computer. Each request was and is handled independently. The server software does not “know” (the “know” is in quotes as an excuse for using such an anthropomorphic term) if a request is from a client computer that has made a request recently or has never made a request before this one. Similarly, no information entered or calculated about the particular site visitor is retained from previous visits or passed on to another Web page on the same site. This design simplifies the workings of the Web, but does not support the requirements of complex applications such as e-commerce.

Here are two examples of situations in which the site builders would want to retain information.

An online application might involve multiple Web pages. One example of this is online shopping. The customers move from catalog pages to specifying details of the order, to catalog pages again, and then to the check-out page. The technical term for this is transaction. The system designer wants to maintain all the information and then execute the complete transaction. For these situations, the information needs to persist for the duration of the time the visitor is seeing the pages belonging to the application.

Many sites require the visitor to log on to the system. Since most of us “belong” in this way to many sites, this means remembering multiple sets of logon ID and passwords. The owners of Web sites would like to simplify the process for their clients. As a gesture of good will, in addition, the owners want to greet each visitor with a personalized welcome. This greeting could, of course, include a customized marketing appeal. For this situation, the site owners want to access the information each time a visitor returns to one of the Web pages on the site.

Cookies were developed to address these types of situations. The term cookies is intended to be a term of innocence and fun. Cookies are small files located on the client computer. These files are written by a specific Web site and used only by code on that Web site. They last for the duration of an invocation of a browser or for a fixed amount of time, which could be days or months.

Session variables are more elaborate mechanisms to hold information over the course of a visit to one or more Web pages located on a single server. The bulk of the session data is kept on the server computer.

You can choose to set your browser to refuse cookies. It is, after all, your computer, and you might not like the idea of someone writing a file to one of your drives. There is a limitation to the number and size of cookies that can be written by any one Web site, and the total number of cookies. For this reason, if you are designing a Web site, you cannot depend on cookies being present.




Creating Database Web Applications with PHP and ASP
Creating Database Web Applications with PHP and ASP (Charles River Media Internet & Web Design)
ISBN: 1584502649
EAN: 2147483647
Year: 2005
Pages: 125
Authors: Jeanine Meyer

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