Description

Runs when a session starts.

Syntax

<cffunction name="onSessionStart" returnType="void">
...
</cffunction>

See also

onSessionEndMethod summaryManaging requests in Application.cfc in Defining the application and its event handlers in Application.cfc in the Developing ColdFusion Applications

Returns

This method does not return a value; do not use the cfreturn tag.

Usage

This method is useful for initializing Session scope data, such as a shopping cart, or setting session-specific Application scope variables, such as for tracking the number of active sessions. You need not lock the Session scope to set its variables using this method.If you call this method explicitly, ColdFusion does not start a session; it does execute the method code, but does not lock the Session scope.This method can access the requested page's Variables scope only if the Application.cfc file includes an onRequest method that calls the page.

Example

The following onSessionStart example initializes some Session scope variables and increments an Application scope counter of active sessions.

<cffunction name="onSessionStart">
<cfscript>
Session.started = now();
Session.shoppingCart = StructNew();
Session.shoppingCart.items =0;
</cfscript>
<cflock scope="Application" timeout="5" type="Exclusive">
<cfset Application.sessions = Application.sessions + 1>
</cflock>
</cffunction>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy