Coldfusion variable types
The following table describes the types of variables you can use in a Coldfusion application page.
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.
Prefix | Required | Availability | Comment |
---|---|---|---|
Variables(Local) | No | Cannot be accessed by a custom tag called by the page or by an action page that differs from a form page that creates the variables | Created by the cfset or cfparam tag by using a Variables prefix or no prefix |
Form | No | Can be used on the action page of a form; cannot be used on a form page that is not also the action page | Created 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. |
URL | No | The target page of a URL | Contains the parameters passed in the URL query string that accesses a page |
Attributes | Yes | On the custom tag page only | Contains the values passed in the custom tag's attributes by the calling page to a custom tag page |
Caller | No 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. |
Request | Yes | On the creating page and in any tags, including nested tags, called after the variable is created | Created by the cfset or cfparam tag by using a Request prefix |
CGI | No | On any page; values are specific to the latest browser request | Created by the Web server. Contains the server environment variables that result from the browser request. |
Cookie | No | For one client, in one or many applications and pages, over multiple browser sessions | Created by the cfcookie tag |
Client | No | For one client in one application over multiple browser sessions | Created by the cfset or cfparam tag by using a Client prefix |
Session | Yes | For one client in one application and one browser session | Created by the cfset or cfparam tag by using a Session prefix |
Application | Yes | For multiple clients in one application over multiple browser sessions | Created by the cfset or cfparam tag by using an Application prefix |
Server | Yes | On any page on the Coldfusion server | Created by the cfset or cfparam tag by using a Server prefix |