Coldfusion variable types

The following table describes the types of variables you can use in a Coldfusion application page.

Variable Type Description
Query ResultResults of a database query can be used as dynamic parameters. For example, if you create a query named Lookupuser that finds the ID for a given user name, you can use this ID in another query or in a call to cfoutput.
Local VariableThe default scope for variables of any type 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 application page where it is created and any included pages.
URL ParameterParameters appended to a URL after the application page name in the format variablename = value. URL parameters are stored in structures.
Form FieldThe most common way of passing parameters to a page. When a user enters data in a form field, a parameter with the name of the form field is passed to the action page. Form fields are stored in structures.
ClientVariables associated with a particular client. Lets you maintain state as a user moves from page to page in an application. Stored in the system registry by default, but you can also store them in a cookie or in a database. Client variables are part of the Coldfusion Web Application Framework. .
ServerVariables associated with the current Web server. Available to all Coldfusion applications until the Coldfusion server is shut down. This server scope lets you define variables that all your Coldfusion application pages can reference.Server variables are stored in structures.
SessionVariables tied to an individual client that persist for as long as that Client ID maintains a session. Session variables, like current client variables, require a client name and are available only to that one 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.Session variables are stored in structures. Session variables should be locked when accessed.Session variables are part of the Coldfusion Web Application Framework. This means that they are used in the context of an Application.cfm page.
ApplicationVariables tied to an application as defined in the CFAPPLICATION NAME attribute, typically used in the Application.cfm file. Application variables work only if an application name is defined.Application variables are stored in structures. Application variables should be locked when accessed. Application variables are part of the Coldfusion Web Application Framework. This means that they are used in the context of an Application.cfm page.
RequestVariables storing data that pertains to the processing of a request to a single page. Request variables are convenient for storing data in a structure, carried through nested tags, such as Custom Tags, and processed at once.Request variables are stored in structures.
CallerVariable that lets you call and use variables from the calling template in a Coldfusion custom tag.
HTTP CookiesVariables stored in the browser. Available every time the browser makes a page request. You can create cookie variables with the cfcookie tag.
FileRead-only variables. Created when a cffile action = "upload" operation is executed.
CGI EnvironmentEvery page request has several environment variables sent to it that relate to the context in which it was requested. The variables available depend on the browser and server software. Note: CGI environment variables are created even when you are using a Web server that supports a server API.

Qualifying, or scoping, variable references

Coldfusion distinguishes between identically named parameters from different sources by using a different prefix for each source. Specifying a variable's source is known as "scoping" the variable. For example, to specify a variable called State that is passed in a form submission, you would reference it as Form.State. To specify a variable named State passed in a URL, you would reference it as URL.State.

Although you are not required to use the scope prefix unless two variables in different scopes have the same name, it is recommended for readability and processing speed that you use prefixes. For example, the variable Form.lastname is clearer than a variable called simply lastname.

Tip:Specify the variable's scope prefix for all Application, Session, Server, and Request variables.

Many CFML tags, such as cferror and cfftp, have variables associated with them. Typically, these variables use the tag name as the prefix. For a list of the variables, see the Quick Reference to CFML.

Note: Any variable that can be created using cfset can also be created with an assignment statement in cfscript.

Scopes and variables

The following table lists the types of variable scopes, and shows how you refer to them in your code. In addition to these scopes, there are a number of Coldfusion data structures that provide information about the results of a tag or operation. For information on special variables, see the CFML Quick Reference and the documentation of the individual CFML tags that return these variables.

PrefixRequiredAvailabilityComment
Variables(Local)NoCannot be accessed by a custom tag called by the page or by an action page that differs from a form page that creates the variablesCreated by the cfset or cfparam tag by using a Variables prefix or no prefix
FormNoCan be used on the action page of a form; cannot be used on a form page that is not also the action pageCreated by the form or cfform tag name attribute. Contains the values of data tags (such as input) in the form body when the form is submitted.
URLNoThe target page of a URLContains the parameters passed in the URL query string that accesses a page
AttributesYesOn the custom tag page onlyContains the values passed in the custom tag's attributes by the calling page to a custom tag page
CallerNo in calling page. Yes in custom tag page.As normal local variables on the page calling the custom tag. Available on the custom tag page by using the Caller scope prefix. Created in a custom tag page cfset or cfparam tag by using a Caller prefix. Created as local variables on the calling tag page.
RequestYesOn the creating page and in any tags, including nested tags, called after the variable is createdCreated by the cfset or cfparam tag by using a Request prefix
CGINoOn any page; values are specific to the latest browser requestCreated by the Web server. Contains the server environment variables that result from the browser request.
CookieNoFor one client, in one or many applications and pages, over multiple browser sessionsCreated by the cfcookie tag
ClientNoFor one client in one application over multiple browser sessionsCreated by the cfset or cfparam tag by using a Client prefix
SessionYesFor one client in one application and one browser sessionCreated by the cfset or cfparam tag by using a Session prefix
ApplicationYesFor multiple clients in one application over multiple browser sessionsCreated by the cfset or cfparam tag by using an Application prefix
ServerYesOn any page on the Coldfusion serverCreated by the cfset or cfparam tag by using a Server prefix