List of Topics

SfC Home > Web Design > SQL > ColdFusion >

Enabling Session Variables in ColdFusion

by Ron Kurtus (21 Janauary 2022)

The standard variables used in ColdFusion can be only transferred or sent to the next page before it is necessary to restate the variable. In some situations, you may want to define a variable that will apply to all the pages during a single session of the user.

Enabling Session Variables in ColdFusion allows you to keep a variable active during a user session.

An example is when the pages a user sees are personalized to his or her specific needs. In such a case, session variables are defined and used.

Questions you may have include:

This lesson will answer those questions.

Session variable persistent

A session variable is one of several types of variables that persist across multiple templates:

Session variables are designed to hold information that you seldom write but are read often.

Define in Application.cfm template

A common method of using session variables is to define them in the Application.cfm template, which is a special ColdFusion page that is processed before the other pages in a session. It usually should be in the session root directory.


To enable the use of session variables, as well as client and application management, you should use the CFAPPLICATION tag in the Application template. A typical tag would be:

SESSIONTIMEOUT="#CreateTimeSpan(0, 0, 20, 0)#">


Setting variables

After the CFAPPLICATION tag, you can set your session variables, using the CFSET tag. You must always refer to session variables with the prefix session. Thus, you could define a session variable, such as:


Should lock variables

You should lock the session variables to avoid problems when several people are using the system at the same time. An example of this is: 

<CFLOCK TIMEOUT="30" NAME="#session.sessionID#" TYPE="Exclusive">

Defined on applicable pages

A problem in using the Application.cfm template is that it is often difficult to change your session variables, once they have been set. An alternative is to use the CFAPPLICATION tag in each applicable page:


You then can define the session variable in the first page, accessed:

<CFSET session.ID="#ID#">

This is a compromise between the standard method and defining the variable on each page.

Example of use

Suppose a user logged in to the site. His name could be sent through a form and entered in Application.cfm. Then the session will constantly refer to him by name.



<CFSET session.namex="#form.othername#">


<H1>Hello #session.namex#</H1>


Session variables is a handy way to define a persistent variable.

Observe and learn

Resources and references

Ron Kurtus' Credentials


Configuring and using session variables - Adobe Help

ColdFusion Resources


(Notice: The School for Champions may earn commissions from book purchases)

Top-rated books on ColdFusion

Students and researchers

The Web address of this page is:

Please include it as a link on your website or as a reference in your report, document, or thesis.

Copyright © Restrictions

Where are you now?

School for Champions

ColdFusion topics

Using Session Variables in Coldfusion

ColdFusion topics


Development methods

Specific applications

Also see

Let's make the world a better place

Be the best that you can be.

Use your knowledge and skills to help others succeed.

Don't be wasteful; protect our environment.

You CAN influence the world.

Live Your Life as a Champion:

Take care of your health

Seek knowledge and gain skills

Do excellent work

Be valuable to others

Have utmost character

Be a Champion!

The School for Champions helps you become the type of person who can be called a Champion.