In order to use session variables, first you have to instruct the Cold Fusion server that you wish to use them.

	<cfapplication name="PickSomeUniqueName"

It would be best to place this inside your Application.cfm file, otherwise you will have to add it in each of your templates before you refrence any session variables. The "SessionTimeout" field defines how long to wait before removing the user's session variables from the system's memory. The syntax is SessionTimeout="days,hours,minutes,seconds". In this case, if the user does not perform any action on your site within 30 minutes, their session variables will dissapear.

Once you set the CFAPPLICATION tag, simply prefix any variables that you want to be access across multiple pages with "session.". For example, once you set the variable "session.userid", all of your pages can use it.

Keep in mind that you'll have to code in some sort of check to see if the session variables have expired. You can either define them with a default value or if the session variable doesn't exist, redirect them to your login page.

	<!--- Check to see if the session variable exists, if not set it. --->
    <CFPARAM name="session.IsLoggedIn" default="N" />

	<!--- Check to see if the session variable exists, if not redirect them to the login page --->
    <CFIF IsDefined("session.IsLoggedIn") EQUAL "No">
    	<CFLOCATION URL="/login.cfm" />

Looking for more ColdFusion tutorials? Visit my ColdFusion Tips & Tricks website!

About This Tutorial
Author: John Bartlett
Skill Level: Beginner 
Platforms Tested: CF5,CFMX,CF8,CF9,BlueDragon,Railo
Total Views: 286,533
Submission Date: September 17, 2002
Last Update Date: August 25, 2011
All Tutorials By This Autor: 1
Discuss This Tutorial
  • i want to kill session when my browser closed, i do not know how to do it. need help please


  • i need you help in how to kill session .. i need it in my senior project.


Sponsored By...
Mobile App Development (IOS, Android, Cordova, Phonegap, Objective-C, Java) - Austin, Texas Mobile Apps - Touch512, LLC.