Much of the programming in the previous several chapters has analogies to most typical nonweb application programming. Almost all applications need to process user inputs, output information, and read and write from databases or other storage media. But in this chapter we will be examining a development problem that is unique to the world of web development: how can one request share information with another request?
Perhaps the best way to visualize the problem of state is illustrated in Figure 15.1. It shows the common scenario of a user login. The question is: how did the server "know" when the user was and was not logged in?

At first glance, this problem does not seem especially formidable. Single-user desktop applications do not have this challenge at all because the program information for the user is stored in memory (or in external storage) and can thus be easily accessed throughout the application. Yet one must always remember that web applications differ from desktop applications in a fundamental way. Unlike the unified single process that is the typical desktop application, a web application consists of a series of disconnected HTTP requests to a web server where each request for a server page is essentially a request to run a separate program, as shown in Figure 15.2. That is, in web applications, state management is an issue since a web application on a server only exists while it is handling a request, but the application experience for the user must be spread across multiple requests.

Furthermore, the web server sees only requests. The HTTP protocol does not, without programming intervention, distinguish two requests by one source from two requests from two different sources, as shown in Figure 15.3.

While the HTTP protocol disconnects the user’s identity from his or her requests, there are many occasions when we want the web server to connect requests together. Consider the scenario of a web shopping cart. In such a case, the user (and the website owner) most certainly wants the server to recognize that the request to add an item to the cart and the subsequent request to check out and pay for the item in the cart are connected to the same individual.
The rest of this chapter will explain how web programmers and web development environments work together through the constraints of HTTP to solve this particular problem. As we will see, there is no single “perfect” solution, but a variety of different ones each with their own unique strengths and weaknesses.