User Guide
Chapter 12: Using the Application Framework 191
Creating a client variable
To create a client variable and set the value of the parameter, use the CFSET or
CFPARAM tag., for example:
<CFSET Client.FavoriteColor="Red">
Once a client variable has been set in this manner, it is available for use within any
application 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 to set a default value if the parameter does not already exist:
<CFPARAM NAME="Client.FavoriteColor" DEFAULT="Red">
Using Client Variables
A client variable is accessed using the same syntax as other types of variables, and can
be used anywhere other ColdFusion variables are used.
To display the favorite color that has been set for a specific user, use the following code:
<CFOUTPUT>
Your favorite color is #Client.FavoriteColor#.
</CFOUTPUT>
Standard client variables
In addition to storing custom client variables, the Client object has several standard
parameters. These parameters can be useful in providing customized behavior
depending on how often users visit your site and when they last visited. For example,
the following code shows the date of a user’s last visit to your site:
<CFOUTPUT>
Welcome back to the Web SuperShop. Your last
visit was on #DateFormat(Client.LastVisit)#.
</CFOUTPUT>
The standard Client object attributes are read-only (they can be accessed but not set by
your application) and include CFID, CFToken, URLToken, HitCount, TimeCreated, and
LastVisit.
Using client state management without cookies
You can use ColdFusion’s client state management without cookies. However,this is
not recommended. If you choose to maintain client state without cookies, you must
ensure that every request carries CFID and CFTOKEN.
To maintain client state without cookies, set the SETCLIENTCOOKIES attribute of the
CFAPPLICATION tag to No. Then, you must maintain client state in URLs. by passing