Adobe ColdFusion 8

Client Variables page

Client variables let you store user information and preferences between sessions. Using information from client variables, you can customize page content for individual users.

You enable client variable default settings in ColdFusion on the Client Variables page of the Administrator. ColdFusion lets you store client variables in the following ways:

  1. In database tables

Note: If your data source uses one of the JDBC drivers bundled with ColdFusion 8, ColdFusion can automatically create the necessary tables. If your data source uses the ODBC Socket or a third-party JDBC driver, you must manually create the necessary CDATA and CGLOBAL database tables.

  • As cookies in users' web browsers
  • In the operating system registry

Important: Adobe recommends that you do not store client variables in the registry because it can critically degrade performance of the server. If you do use the registry to store client variables, you must allocate sufficient memory and disk space.

To override settings specified in the Client Variables page, use the Application.cfc file or the cfapplication tag. For more information, see the ColdFusion Developer's Guide.

The following table compares the client variable storage options:

Storage type

Advantages

Disadvantages

Data source

  • Can use existing data source
  • Portable: not tied to the host system or operating system
  • Requires database transaction to read/write variables
  • More complex to implement

Browser cookies

  • Simple implementation
  • Good performance
  • Can be set to expire automatically
  • Client-side control
  • Users can configure browsers to disallow cookies
  • Cookie data is limited to 4 KB
  • Netscape Navigator allows only 20 cookies from one host; ColdFusion uses three cookies to store read-only data, leaving only 17 cookies available

System registry

  • Simple implementation
  • Good performance
  • Registry can be exported easily to other systems
  • Server-side control
  • Possible restriction of the registry's maximum size limit in Windows in the Control Panel
  • Integrated with the host system: not practical for clustered servers
  • Not available for UNIX

Migrating client variable data

To migrate your client variable data to another data source, you should know the structure of the database tables that store this information. Client variables stored externally use two simple database tables, like those shown in the following tables:

CDATA Table

Column

Data type

cfid

CHAR(64), TEXT, VARCHAR, or equivalent

app

CHAR(64), TEXT, VARCHAR, or equivalent

data

MEMO, LONGTEXT, LONG VARCHAR, or equivalent

CGLOBAL Table

Column

Data type

cfid

CHAR(64), TEXT, VARCHAR, or equivalent

data

MEMO, LONGTEXT, LONG VARCHAR, or equivalent

lvisit

TIMESTAMP, DATETIME, DATE, or equivalent

Creating client variable tables

Use the following sample ColdFusion page as a model for creating client variable database tables in your own database. However, keep in mind that not all databases support the same column data type names. For the proper data type, see your database documentation.

Note: The ColdFusion Administrator can create client variable tables for data sources that use one of the bundled JDBC drivers. For more information, see the online help.

Sample table creation page

<!---- Create the Client variable storage tables in a datasource. 
This example applies to Microsoft Access databases. --->

<cfquery name="data1" datasource="#DSN#">
CREATE TABLE CDATA
(
cfid char(20),
app char(64),
data memo
)
</cfquery>

<cfquery name="data2" datasource="#DSN#"> 
    CREATE UNIQUE INDEX id1 
    ON CDATA (cfid,app)
</cfquery>
 
<cfquery name="global1" datasource="#DSN#">
CREATE TABLE CGLOBAL
(
cfid char(20),
data memo,
    lvisit date
)
</cfquery>

<cfquery name="global2" datasource="#DSN#"> 
    CREATE INDEX id2 
    ON CGLOBAL (cfid)
</cfquery>

<cfquery name="global2" datasource="#DSN#"> 
    CREATE INDEX id3 
    ON CGLOBAL (lvisit)
</cfquery>