eWebProgrammer eweb

ASP   «Prev  Next»
Lesson 7Request.Cookies
ObjectiveRead user data written during a prior visit.
HTTP is known as a "stateless" protocol.
After a browser and server have completed an HTTP transaction, no information (such as data submitted through an HTML Form) is retained. This loss of user information occurs when the user moves from page to page in a Web site and when a user leaves one Web site for another.
Cookies were developed as a way to retain user data between Web pages or visits to a Web site.
A cookie consists of one or more name-value pairs sent to a browser from a Web server. The browser stores these cookies in a text file (called cookie.txt).
Although you cannot store much information in any one cookie, they are still useful for:
  1. Identifying returning users: Many sites store a unique user ID in a cookie and then use the cookie value to retrieve user information from a database.
  2. Tracking a user's order: Many sites that maintain "shopping carts" to store a record of items to be purchased use cookies to track the cart's contents.
  3. ASP's Session object: The ASP Session object uses a session cookie (different from a browser cookie) to retain user information as the user goes to various parts of the Web site.

Reading a T-shirt cookie
<TD>Preferred size:</TD>
<TD><%= Request.Cookies("ShirtSize") %></TD>
And here is what is displayed on the user's browser:
Preferred size: XXL
Multiple-value cookies