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:
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 |
|
|
Browser cookies |
|
|
System registry |
|
|
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.
<!---- 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>