Now that you’ve enabled client management, you are ready to start creating and using client variables. Client variables are set and accessed in basically the same manner as standard variables. The difference, of course, is that client variables are persistent and can be referenced from any template within a ColdFusion application.
Creating Client Variables
To create a client variable, you must use the CFSET or CFPARAM tags. You must also scope your variable name with the prefix client. If you do not scope the variable with current, then it will be created as a standard ColdFusion variable and only be accessible to the current template. The following code sets a passed form field equal to the client variable client user_name.
Referring to Client Variables
Referring to client variables is as simple as creating them. Just follow the standard rules for accessing any variable. Remember that when you refer to a variable within a ColdFusion tag, you generally do not need to use pound signs. Here are two examples of referring to the client variable client . user_name
Using Variable Prefixes and Seoping Your Variables
You should get into the habit of scoping your variables by always using variable prefixes. For example, use client. var1 instead of var1. This reduces the processing time that Cold Fusion takes to evaluate the variable. If you don’t use prefixes, variables will be evaluated in the following order:
1. Regular variables
2. CGI variables
3. File variables
5. Form variables
6. Cookie variables
7. Client variables
You may notice that apptication, server, and session variables (discussed in subsequent sections of this chapter) are not included in the preceding list. This is because prefixes for these variables must be specified. Otherwise, Cold Fusion will return an error. If you have a form variable called MyVar and a client variable by the same name (and you don’t specify the prefix), ColdFusion will always return the value of the form variable, because form variables are evaluated first.
Using Built-In Client Variables’
You can refer to several built-in client variables in your ColdFusion applications. These built-in client variables are stored in the registry by default and are tied to a specific CFID and (FTOKEN).
Retrieving a List of Client Variables
To retrieve a list of all currerly set client variables, use the Get Client variables List function. This function returns a comma-delimited list of all client variable names except the built-in client variables To display a list of client variable names, use the following code.
Client variables currently available for use are: #Get(lientVariablesList()#