I was recently working on a website and trying to set a session variable - but for the life of me I couldn't get the session variable to get set and stick. I had done it a million times before, and I couldn't figure out why it wasn't working. After taking a few minutes to research it I remembered that you have to set session management to true in the application.cfm file.
The application.cfm file is a file that you can place in the root directory or any other directory and all files in that directory or in another directory in that same directory will have access to the values set in the application.cfm file.
To enable session management for the website you'll need to place the following code in the application.cfm file.
<CFAPPLICATION NAME="Name"
SESSIONMANAGEMENT="Yes"
SESSIONTIMEOUT="#CreateTimeSpan(0, 0, 20, 0)#">
If you need to increase the session timeout then you can go ahead and do that. Now in order to set a session variable on any page you just set it like a regular coldfusion variable with the <cfset tag.
<cfset session.mysessionvariablename = "This is the session variable value">
And to grab this session variables value is as simple as:
<cfoutput>#session.mysessionvariablename#</cfoutput>