Client Variables

Client variables let you perform tasks like determining the IP address of a site visitor's Web browser. Using information from client variables, you can customize page content for individual users.

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


Note

You can override settings specified in the Client Variables page using the attributes of the cfapplication tag. For more information, see the Developing ColdFusion Applications


The following table compares these storage options
Storage Type
Advantage
Disadvantage
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 on Windows NT and WIndows 2000 in the Control Panel
  • Integrated with the host system: not practical for clustered servers
  • Solaris, Linux, and HP-UX registries are text files. Their registries deliver slow performance and low scalability.
Browser cookies
  • Simple implementation
  • Good performance
  • Can be set to expire automatically
  • Client-side control
  • Users can configure browsers to disallow cookies
  • ColdFusion Server limits a cookie's data to 4 KB
  • Netscape Navigator allows only 20 cookies from one host; ColdFusion Server uses three cookies to store read-only data, leaving only 17 cookies available
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
:


Note

If you use the registry to store client variables, ensure that enough memory is allocated for it.


To enable client variable storage in the registry as the default:

  1. In the Client Variables page, select Registry. Click Apply.
  2. To display a page in which to enable the automatic deletion of variables that have not been used for a specified number of days, click Registry. Click Submit Changes.

To enable client variable storage in cookies as the default:

In the Client Variables page, select Cookie. Click Submit Changes.

To enable client variable storage in a data source as the default:

  1. In the Client Variable page, select a data source in the drop-down list.
  2. Click Add Client Variable Storage. The Add/Edit Client Store page for your data source displays.
  3. On the Add/Edit Client Store page, select options for the data source, as described in the following table. If you do not want to make changes, return to the Client Variables screen using one of the arrows on the page.
    Option
    Description
    Purge data for clients that remain unvisited for [n] days
    Enable this option to periodically purge client data that has not been accessed in a specified number of days, and enter a number.
    Disable global client variable updates
    Enable this option to prevent ColdFusion Server from updating client variables for every page request. When updates are disabled, ColdFusion Server only updates global client variables when they are created and when they are changed. Disabling updates helps improve the performance of application pages.
    Create Client database tables
    Enable this option only when you configure a data source for client variable storage the first time. ColdFusion Server creates the tables necessary for client variables. If the data source has already been configured, disable this option. Otherwise, ColdFusion Server generates an SQL error because it tries to create tables that already exist.
  4. Click Submit Changes.

    Note

    If a cluster of ColdFusion Servers uses this data source, ensure that only one server is configured to purge client data.


Migrating Client Variable Data

To migrate your client variable data to another data source, you should know the structure of the database tables used to store this information. Client variables stored externally use two small database tables like those shown in the following tables:
CGLOBAL Table
Column
Data Type
cfid
char(64)
data
memo
lvisit
date
CDATA Table
Column
Data Type
cfid
char(64)
app
char(64)
data
memo

Creating client variable tables

Use this example 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. Refer to your database documentation for the proper data type.

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>



Banner.Novgorod.Ru