Client
|
|
Advantages |
Disadvantages |
|---|---|
|
|
You might choose to store your client variables in simple cookies on the client machine. You need to be aware that you face the standard limitations of cookies and user preferences regarding them. Cookies perform well and are easy to implement, but you might want to consider all the pros and cons of storing client variables in cookies, as outlined in Table 8.4.
|
Advantages |
Disadvantages |
|---|---|
|
|
Storing client variables in a database of their own is a great idea for a number of reasons. However, it also has its downsides. Table 8.5
|
Advantages |
Disadvantages |
|---|---|
|
|
Of the variable scopes used to maintain user state, client variables are the one solution that could really be
Client variables are created just like many of the other variable scopes in ColdFusion, by using the CFSET or CFPARAM tags.
<cfset client.AppStyle="Patriotic">
or
<cfparam name="client.AppStyle" default="Standard">
After you have set the client variable, it is available for use within any page in the application for the particular client that set the variable. By using the CFPARAM tag to set a default value for the variable name, you can be assured that you can always use the variable without using a CFIF statement to evaluate the variable's existence.
Accessing client variables is easy. You don't have to refer to their storage method or anything like that; you simply call the variable name with the client scope:
<cfoutput> Show the application in the #client.AppStyle# theme. </cfoutput>
If you're not sure what client variables are currently available to a client, you can always call the CFDUMP tag to output the client structure. However, this shows you all the existing client variables. If you only want to output the custom variables that have been created through the application, you can use the GetClientVariablesList() function:
<cfoutput>#GetClientVariablesList()#</cfoutput>
Because client variables are held in a structure, you can delete or manipulate client variables with any of the standard structure functions. There is, however, another method of deleting a client variable. You can use ColdFusion's DeleteClientVariable() function:
<cfset tmp=DeleteClientVariable("client.AppStyle")>
Only custom client variables can be deleted. This excludes the default client variables (see Table 8.6). Client variables can also be timed out. Within the ColdFusion MX Administrator, you can set default timeouts for your client variables.
If you call a CFLOCATION when using client variables in your application, the CFID and CFTOKEN automatically are appended to your URL when you are calling a CFM or DBM page. You can disable this feature by adding the addtoken attribute to your CFLOCATION tag and specifying the following:
<cflocation url="/index.cfm?display=News" Addtoken="No">
If you need to pass other parameters along the URL, you can run into trouble with the automatic inclusion of CFID and CFTOKEN . What happens is that the automatically included parameters are formatted as ?CFID=3&CFTOKEN=39297791 . The problem occurs when this is appended to a URL that already has URL parameters included. The resulting URL call might look like this:
http://www.insidecoldfusionmx.com/index.cfm?display_code=News?CFID=3&CFTOKEN=39297791
Errors will result.
As with many of our other variable scopes, there are a few client variables that are predefined. The client scope has six built-in, read-only variables. These are outlined in Table 8.6.
|
Variable |
Description |
|---|---|
|
Client.CFID |
The client ID. |
|
Client.CFToken |
The client security token. |
|
Client.URLToken |
A concatenation of CFID and CFTOKEN . Stored as CFID=123&CFTOKEN=23457323 . This variable is useful if the client does not support cookies and you must pass the CFID and CFTOKEN values. |
|
Client.HitCount |
The number of page
|
|
Client.LastVisit |
The last time the client visited the application. |
|
Client.TimeCreated |
The time at which the CFID and CFTOKEN variables of the client were created. |