Runs when a session starts.
<cffunction name="onSessionStart" returnType="void"> ... </cffunction>
onSessionEnd
, Method summary, Managing sessions in Application.cfc in ColdFusion MX Developer's Guide
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 never need to 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 and 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>