CLIENT Variables


CLIENT Variables

Like COOKIE and SESSION variables, CLIENT variables are specific to one user. However, rather than being stored on the client machine or in the server's memory, CLIENT variables are stored elsewhere.

CLIENT variables can store only simple data (like numbers and strings), not complex data (like arrays, structures, and queries).

Preparing CLIENT Variable Storage

CLIENT variables, like SESSION variables, are also tied to an application and must be enabled before they can be used:

  • If using Application.cfc, use <cfset THIS.clientManagement="true"> to enable client use, and THIS.clientStorage to specify their storage location.

  • If using Application.cfm, use <cfapplication clientManagement="true"> to enable client use, and the clientStorage attribute to specify their storage location.

There are three locations where you can store CLIENT variables. They are discussed in Table 11.2 and can be set in the ColdFusion Administrator.

Table 11.2. Storage Locations for CLIENT Variables

STORAGE LOCATION

DESCRIPTION

Data source

A specific data source can be used to store CLIENT variable data.

Registry

CLIENT variables can be stored in the Registry (Windows only).

Cookie

CLIENT variables can be stored in cookies.


CAUTION

Your system can become unstable or unusable if your registry holds too much data. As a general rule, registry use should be avoided.


If you set CLIENT variable storage to a data source, you will find that the ColdFusion application server creates two tables called CDATA and CGLOBAL in the data source for this purpose.

Cookies can be a good place to store CLIENT variable IDs, but all the limitations you have learned about cookies remain true in this case.

There is one special advantage to CLIENT variables: Because they can be stored in a database, they can be used by multiple servers (perhaps in a cluster), since those servers can share the same database. As such, CLIENT variables are invaluable in the right situation.

Creating CLIENT Variables

CLIENT variables are the only way to reliably store information about one user over multiple sessions. Although you can do this with cookies, the fact that COOKIE variables can be easily deleted or modified makes them less reliable.

You create CLIENT variables using <cfset> and prefixing the variable name with CLIENT:

 <cfset CLIENT.FirstName="Emily"> 

You can also use <cfparam> to set default values for this variable.

Using CLIENT Variables

To use CLIENT variables, you just prefix them appropriately:

 <cfoutput>#CLIENT.FirstName#</cfoutput> 

The output of the preceding line will display the name Emily.



Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net