The Web is a stateless environment. Every HTTP request or response to your Web server opens a connection, but after the action has completed, the connection is closed. These requests and responses contain no information to tell the server to associate a request with previous or subsequent requests. Session state is the process of associating a series of HTTP requests and responses with a unique user, and keeping a set of variables for that session. NOTE A user session, not to be confused with a session variable, is defined as a related series of HTTP requests and responses for a particular user. Each session has a lifetime, typically the length of time the user's browser is actively connected to the Web site. ColdFusion gives you several powerful tools for managing session state. These tools range from flexible manipulation of browser-based cookies to a full set of CLIENT- and SESSION-based variables. This chapter discusses these methods, but you should note that each method of session-state management poses some serious implications. When you manage state, you force the Web to do something it wasn't originally built to perform. Managing session state becomes especially complex if you are planning to scale your ColdFusion application across multiple ColdFusion servers. In this chapter, you will learn how to manage state in a clustered environment using various techniques, including ColdFusion CLIENT variables, ColdFusion SESSION variables in conjunction with a SESSION-aware load-balancing solution, and storing user information in client-side cookies. You will also learn about Java SESSION variables, which have a number of advantages over traditional ColdFusion session variable. Managing state can be difficult and detailed, depending on which option you choose. Choose carefully: If you are basing your application on saving state, clustered environments introduce a whole new set of issues. Each of the techniques described in this chapter involve different coding methods. It is important to determine the appropriate strategy for your application early in the development process, preferably before coding begins. |