User Guide

Table Of Contents
Configuring and using client variables 349
This.clientStorage="mydatasource";
</cfscript>
The following code from an Application.cfm file does the same thing as the previous example:
<cfapplication name"SearchApp"
clientmanagement="Yes"
clientstorage="mydatasource">
Using client variables
When you enable client variables for an application, you can use them to keep track of long-term
information that is associated with a particular client.
Client variables must be simple data types: strings, numbers, lists, Booleans, or date and time
values. They cannot be arrays, record sets, XML objects, query objects, or other objects. If you
must store a complex data type as a client variable, you can use the
cfwddx tag to convert the data
to WDDX format (which is represented as a string), store the WDDX data, and use the
cfwddx
tag to convert the data back when you read it. For more information on using WDDX, see
Chapter 35, “Using WDDX,” on page 879.
Note: When saving client variable data in WDDX format, in the case of the registry and SQL Server,
the limit is about 4K; with ORACLE, the limit is about 2K.
Creating a client variable
To create a client variable and set its value, use the
cfset or cfparam tag and use the Client scope
identifier as a variable prefix; for example:
<cfset Client.FavoriteColor="Red">
After you set a client variable this way, it is available for use within any page in your application
that is accessed by the client for whom the variable is set.
The following example shows how to use the
cfparam tag to check for the existence of a client
parameter and set a default value if the parameter does not already exist:
<cfparam name="Client.FavoriteColor" default="Red">
Accessing and changing client variables
You use the same syntax to access a client variable as for other types of variables. You can use client
variables anywhere you use other ColdFusion variables.
To display the favorite color that has been set for a specific user, for example, use the following
code:
<cfoutput>
Your favorite color is #Client.FavoriteColor#.
</cfoutput>
To change the client’s favorite color, for example, use code such as the following:
<cfset Client.FavoriteColor = Form.FavoriteColor>