Runs when a session starts.


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

See also

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


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


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.


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

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


Get help faster and easier

New user?