View Full Version : ColdFusion Session sample - This sample will verify ColdFusion Session

June 12th, 2009, 12:10 PM
By default the Session Timeout is set to 20 minutes.

Here is a sample script to verify the ColdFusion Session variables and ColdFusion Session in general is working.

I'm sure there is an easier way to test this, but here is what I did. I created 2 pages. The first page sets the Session variables. The second page keeps adding to the counter and displaying the count, when the session started, and the current time.

This is handled differently based on whether you are using application.cfm or application.cfc, so be sure to note which one you are using.
If using application.cfm, you need to make sure your application.cfm file is set to handle session variables. To do this, make sure you have sessionmanagement="yes" like:

<cfapplication sessionmanagement="yes">

If using application.cfc, you need to make sure your application.cfc is set to handle the sessions variables properly. Here is an example for that:

<cfset This.name = "myApplication">
<cfset This.Sessionmanagement = TRUE>

In the first page (ie, cfsessiontest.cfm) add this code:

<cfset SESSION.MyCount = 1>
<cfset SESSION.StartTime = Now()>
Current Count is: <cfoutput>#SESSION.MyCount#</cfoutput><BR>
Session Started at: <cfoutput>#SESSION.StartTime#</cfoutput><BR>
<A HREF="cfsessiontest2.cfm">Test Session</A>

Now create a new page named cfessiontest2.cfm and add this code:

<cfset SESSION.MyCount = #SESSION.MyCount# + 1>
Current Count is: <cfoutput>#SESSION.MyCount#</cfoutput><BR>
The current time is <cfoutput>#Now()#</cfoutput> and the Session Started at: <cfoutput>#SESSION.StartTime#</cfoutput><BR>
<A HREF="cfsessiontest2.cfm">Test Session</A>

The first page will load the 2nd page and the 2nd page will keep loading itself when you click on the Test Session link.

October 23rd, 2009, 11:13 PM
To properly use the code samples in this original post to verify ColdFusion Session Variables are working, rename your application.cfc or application.cfm to something like application.old.

Then create the 3 files mentioned and perform the test.