| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
HTTP State Management Using "Cookies" (Page 1 of 3) Even though the modern Hypertext Transfer Protocol has a lot of capabilities and features, it is still, at its heart, a simple request/reply protocol. One of the unfortunate problems that results from this is that HTTP is entirely stateless. This means that each time a server receives a request from a client, it processes the request, sends a response, and then forgets about the request. The next request from the client is treated as independent of any previous ones.
So why is this a problem? Isnt this what we would expect of a protocol designed to allow a client to quickly and efficiently retrieve resources from a server? Well, this is, yet again, another place where HTTPs behavior was well-suited to its original intended uses, but not to how the Web is used today. Sure, if all we want to do is to say hey server, please give me that file over there, then the server doesnt have to care about whether or not it may have previously provided that client with any other files in the past. This is how HTTP was originally intended to be used. Today, as most of us know, the Web is much more than a simple resource-retrieval protocol. If you go to an online store, you want to be able to select a number of items to put into a shopping cart, and have the stores server remember them. You might also want to participate in a discussion forum, which requires you to provide a user name and password in order to post a message. Ideally, the server should let you log in once and then remember who you are so you can post many messages without having to enter your login information each and every time. (I have used forums where the latter is requiredit gets old very quickly, believe me.) For these and other interactive applications, the stateless nature of HTTP is a serious problem. The solution was the addition of a new technology, called state management, that allows the state of a client session with a server to be maintained across a series of HTTP transactions. Initially developed by Netscape, this technique was later made a formal Internet standard in RFC 2109, later revised in RFC 2965 (HTTP State Management Mechanism). Note that this feature is actually not part of HTTP; it is an optional element, but one that has been implemented in pretty much all Web browsers due to its usefulness. The idea behind state management is very simple. When a server implements a function that requires state to be maintained across a set of transactions, it sends a small amount of data to the Web client called a cookie. The cookie contains important information relevant to the particular Web application, such as a customer name, items in a shopping cart, or a user name and password. The client stores the information in the cookie, and then uses it in subsequent requests to the server that set the cookie. The server can then update the cookie based on the information in the new request and send it back to the client. In this manner, state information can be maintained indefinitely, allowing the client and server to have a memory that persists over a period of time.
Home - Table Of Contents - Contact Us The TCP/IP Guide (http://www.TCPIPGuide.com) Version 3.0 - Version Date: September 20, 2005 © Copyright 2001-2005 Charles M. Kozierok. All Rights Reserved. Not responsible for any loss resulting from the use of this site. |