ColdFusion (CFML)

← Back to Home

Note: This is a reference page with static code examples. ColdFusion requires Adobe ColdFusion Server or the open-source Lucee server, which are not installed on this server.

Overview

Released: 1995 by Allaire (now Adobe)

File Extension: .cfm, .cfc

Server Required: Adobe ColdFusion or Lucee (open-source)

Language: CFML (ColdFusion Markup Language) - tag-based

ColdFusion pioneered the concept of tag-based server-side scripting. Instead of embedding code in delimiters like PHP or ASP, ColdFusion uses custom HTML-like tags prefixed with "cf". This made it very accessible to web designers who were already familiar with HTML.

ColdFusion was particularly popular for rapid application development and database-driven websites. It remains in use in government and enterprise environments.

Hello World

ColdFusion uses <cfoutput> tags to output dynamic content, with variables wrapped in # symbols:

<!DOCTYPE html> <html> <head> <title>Hello, ColdFusion!</title> </head> <body> <h1>Hello, ColdFusion!</h1> <p>This page was generated with ColdFusion</p> <cfoutput> <p>Current time: #Now()#</p> <p>Your IP: #CGI.REMOTE_ADDR#</p> </cfoutput> </body> </html>

Environment Variables (CGI Scope)

ColdFusion accesses server variables through the CGI scope:

<cfloop collection="#CGI#" item="key"> <cfoutput> <b>#key#:</b> #CGI[key]#<br> </cfoutput> </cfloop>

Form Handling (GET)

URL parameters are accessed via the URL scope:

<!--- Check if parameter exists ---> <cfif structKeyExists(URL, "name")> <cfoutput> <p>Hello, #htmlEditFormat(URL.name)#!</p> </cfoutput> <cfelse> <p>No name provided</p> </cfif>

Form Handling (POST)

POST data is accessed via the FORM scope:

<cfif structKeyExists(FORM, "username")> <cfoutput> <p>Posted username: #htmlEditFormat(FORM.username)#</p> </cfoutput> </cfif>

Sessions

ColdFusion has built-in session management via the SESSION scope:

<!--- Enable sessions in Application.cfc or at top of page ---> <cfapplication name="MyApp" sessionmanagement="yes"> <!--- Store in session ---> <cfset SESSION.username = FORM.username> <!--- Retrieve from session ---> <cfoutput>#SESSION.username#</cfoutput> <!--- Clear session ---> <cfset structClear(SESSION)>

Database Access

One of ColdFusion's strengths was easy database access with <cfquery>:

<cfquery name="getUsers" datasource="myDB"> SELECT * FROM users WHERE active = 1 </cfquery> <cfoutput query="getUsers"> <p>#username# - #email#</p> </cfoutput>
Proprietary Technology: Adobe ColdFusion requires expensive licensing. The open-source alternative Lucee provides similar functionality for free.

← Back to Home