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
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...