Adobe ColdFusion 8

Configuring and enabling session variables

To use session variables, you must enable them in two places:

  • ColdFusion Administrator
  • The Application.cfc initialization code This.sessionManagement variable or the active cfapplication tag.

ColdFusion Administrator, Application.cfc, and the cfapplication tag also provide facilities for configuring session variable behavior, including the variable time-out.

Selecting and enabling session variables in ColdFusion Administrator

To use session variables, they must be enabled on the ColdFusion Administrator Memory Variables page. (They are enabled by default.) You can also use the Administrator Memory Variables page to do the following:

  • Select to use ColdFusion session management (the default) or J2EE session management.
  • Change the default session time-out. Application code can override this value. The default value for this time-out is 20 minutes.
  • Specify a maximum session time-out. Application code cannot set a time-out greater than this value. The default value for this time-out is two days.

Enabling session variables in your application

You must also enable session variables in the initialization code of your Application.cfc file or in the cfapplication tag in your Application.cfm file.

Do the following in the Application.cfc initialization code, below the cfcomponent tag, to enable session variables:

  • Set This.sessionManagement="Yes".
  • Set This.name to specify the application's name.
  • Optionally, set This.sessionTimeout to set an application-specific session time-out value. Use the CreateTimeSpan function to specify the number of days, hours, minutes, and seconds for the time-out.

Do the following in the Application.cfm file to enable session variables:

  • Set sessionManagement="Yes"
  • Use the name attribute to specify the application's name.
  • Optionally, use the sessionTimeout attribute to set an application-specific session time-out value. Use the CreateTimeSpan function to specify the number of days, hours, minutes, and seconds for the time-out.

The following sample code enables session management for the GetLeadApp application and sets the session variables to time out after a 45-minute period of inactivity:

<cfapplication name="GetLeadApp" 
    sessionmanagement="Yes"
    sessiontimeout=#CreateTimeSpan(0,0,45,0)#>