User Guide

Managing the Client State 221
Managing the Client State
Because the Web is a stateless system, each connection that a browser makes to a
Web server is unique to the Web server. However, within an application it is
important to be able to keep track of users as they move through the pages within the
application. This is the definition of client state management.
ColdFusion provides tools to maintain client state by seamlessly tracking variables
for a browser as the user moves from page to page within the application. These
variables can be used in place of other methods for tracking client state, such as
using URL parameters, hidden form fields, and HTTP cookies.
About Client and Session variables
ColdFusion provides you with two tools for managing the client state: Client
variables and Session variables. Both types of variables are tied to a specific client,
but they have significant differences in how they are managed and when they should
be used:
As a general rule, it is best to use Session variables for any values that need to exist for
only a single browser session. You should reserve Client variables for client-specific
data that you want available for multiple browser sessions, such as client
preferences.
Variable Type Description
Client Data saved as cookies, database entries, or Registry entries, but is
accessed more slowly than data stored in memory.
Each type of data storage has its own timeout period. You can
specify the database and Registry data timeouts in ColdFusion
Administrator. Cookie life depends on the users system.
Data is stored on a per-application basis. For example, if you store
Client variables as cookies, the user has a separate cookie for
each ColdFusion application provided by a server.
Client variables must be strings (or represented as strings). They
cannot be arrays or structures.
You do not need to lock code that uses Client variables.
Session Data is stored in memory so it is accessed quickly.
Data is lost when the client browser is inactive for a timeout period.
You specify the timeout in the ColdFusion Administrator and
Application.cfm.
Data is available to a single application only.
Session variables can be any ColdFusion Data type.
You can access the Session scope as a ColdFusion structure.
You must lock Session code that uses variables to prevent
simultaneous access, for example from different frames.