Coldfusion is a server side, similar to that of PHP or ASP/.NET. Coldfusion is unique in the sense that Coldfusion MX 7 code is compiled into Java bytecode. Currently owned by Adobe, you typically will only find coldfusion running on windows servers.
The syntax of programming in Coldfusion Markup Language (CFML) is similar to HTML or XML. You will need to name your files with a .cfm extension, and the webserver will interpret the page and perform any coldfusion necessary before outputting the HTML or other text naturally sent to the browser.
Lets echo out some output. We use the cfoutput tag.
<cfoutput>Hello World</cfoutput>
Coldfusion is weakly typed, meaning that you do not have to specify the data type per variable. CF determines the data type of a variable at the time the variable is used. A common way to set variables is using the cfset tag.
<cfset name = "Adam" />
<cfset somenumber = 10 />
In ColdFusion, variable names consist of letters, digits, underscores and dollar signs. Variable names are case insensitive. Variable names cannot begin with a digit.
There are different kinds of variable scope.
Variable Scope| Scope | Prefix | Description |
|---|
| Local | VARIABLES | Defined and accessible on the current page only. |
| CGI | CGI | Accessible on any page. Contains server environment variables. |
| URL | URL | Accessible on the current page. Contains values passed in on the query string. |
| Form | FORM | Accessible on the current page. Contains values passed in through a form. |
| Cookie | COOKIE | Accessible on any page. Contains variables held in cookies on the client machine. |
| Client | CLIENT | Accessible on any page. Contains variables created using the Client prefix. |
| Arguments | ARGUMENTS | Defined and accessible within a user-defined function or a ColdFusion Component method. |
| Session | SESSION | Prefix Required. Accessible on any page to a single user for the duration of a client session. |
| Application | APPLICATION | Prefix Required. Accessible on any page to all users until the application is restarted. |
| Server | SERVER | Prefix Required. Accessible on any page that is delivered from specific server. |
ColdFusion will search through the scopes in the following order:
- Arguments
- Local (Variables)
- CGI
- URL
- Form
- Cookie
- Client
We used the cfoutput tag earlier to output text. We encapsulate variable names in pound signs (#) to output a variable using the cfoutput tag.
<cfset str = "Hello" />
<html>
<body>
<cfoutput>#VARIABLES.str# World!</cfoutput>
</body>
</html>