ColdFusion 9.0 Resources |
onSessionEndSyntax<cffunction name="onSessionEnd" returnType="void"> <cfargument name="SessionScope" required=True/> <cfargument name="ApplicationScope" required=False/> ... </cffunction> See alsoonSessionStart, Method summary, Managing sessions in Application.cfc in the Developing ColdFusion Applications ParametersColdFusion passes the following parameters to the method:
UsageUse this method for any clean-up activities when the session ends. A session ends when the session is inactive for the session time-out period. You can, for example, save session-related data, such as shopping cart contents or whether the user has not completed an order, in a database, or do any other required processing based on the user’s status. You might also want to log the end of the session, or other session-related information, to a file for diagnostic use. If you call this method explicitly, ColdFusion does not end the session; it does execute the method code, but does not lock the Session. You cannot use this method to display data on a user page, because it is not associated with a request. You can access shared scope variables as follows:
Sessions do not end, and the onSessionEnd method is not called when an application ends. The onSessionEnd does not execute if there is no active application, however. ExampleThe following method decrements an Application scope session count variable and logs the session length. <cffunction name="onSessionEnd"> <cfargument name = "SessionScope" required=true/> <cfargument name = "AppScope" required=true/> <cfset var sessionLength = TimeFormat(Now() - SessionScope.started, "H:mm:ss")> <cflock name="AppLock" timeout="5" type="Exclusive"> <cfset Arguments.AppScope.sessions = Arguments.AppScope.sessions - 1> </cflock> <cflog file="#This.Name#" type="Information" text="Session #Arguments.SessionScope.sessionid# ended. Length: #sessionLength# Active sessions: #Arguments.AppScope.sessions#"> </cffunction> |