![]() ![]() ![]() |
ColdFusion supports several types of variables. This section describes the types of variables available and how you use them.
The following table describes the types of variables you can use in a ColdFusion application page.
ColdFusion Variable Types | |
---|---|
Variable Type |
Description |
Queries |
As soon as a query has been run, you can use its results as dynamic parameters. For example, if you create a query named LookupUser that finds the ID for a given user name, you might want to use this ID in another query or in a CFOUTPUT. |
Local Variables |
This is the default scope for variables created with the CFSET and CFPARAM tags. For example, <CFSET A=5> sets the variable A to 5. This variable is available only on the page where it is created and any included pages. |
URL Parameters |
Parameters appended to URLs after the application page name using a variablename=value format. |
Form Fields |
The most common way of passing parameters to a page is to use form fields. When a user enters data in a form field, a parameter with the name of the form field is passed to the action page. |
Client |
ColdFusion client variables are variables associated with a particular client. Client variables allow you to maintain state as a user moves from page to page in an application. They are stored in the system registry by default, but you can also choose to store them in a cookie or in a database. For more information, see the Using the Application Framework chapter of this book. |
Server |
ColdFusion server variables are associated with the current Web server and are available to all ColdFusion applications until the ColdFusion server is shut down. This server scope allows you to define variables that all your ColdFusion application pages can reference. |
Session |
Session variables are tied to an individual client and persist for as long as that Client ID maintains a session. Session variables, like current client variables, require a client name to work and are only available to that Client ID. Unlike client variables, session variables are stored in the server's memory and can be set to time-out after a precise period of inactivity. |
Application |
Application variables are tied to an individual application as defined in the CFAPPLICATION NAME attribute, typically used in the Application.cfm file. Application variables only work if an application name has been defined.For more information about the Application.cfm file, see the Using the Application Framework chapter of this book. |
HTTP Cookies |
HTTP Cookie variables are stored in the browser. They are available every time the browser makes a page request. You can create cookie variables with the CFCOOKIE tag. |
CGI Environment |
Every page request has several environment variables sent to it that relate to the context in which it was requested. The variables available will depend on the browser and server software in use for a given request. Note: CGI environment variables are created even when you are using one of the Web servers that supports a server API. |
The section How ColdFusion looks up variables describes the order in which ColdFusion finds variables in application pages.
Within ColdFusion, most variables apply only to a single template. However, four types of variables can be used across multiple application pages:
Client variables are designed to hold long-term information particular to an individual client. You can store client variables in the system registry, a database, or in a cookie named for the application.
Server variables are used to store information (typically read-only) that does not change often and can be shared across many users and ColdFusion applications.
Session variables are useful for storing short-term information needed for a single site visit or set of requests. They are specific to individual users.
Application variables are available to individual, specified applications and to all users of that application who access your ColdFusion server. They are stored in the server's memory and can be set to time out at specified intervals. Application variables are general and available to all users.
In cases where variables are available to several application pages, make sure to keep your variable names straight. See Variable names in this chapter for more information.
![]() ![]() ![]() |
AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.