Answered
Need help with application.cfc
Here is what I am trying to do. I have a login page, and when
a user logs in it verifies their credentials. If everything is good
it sets a session variable called #session.username#. What I want
to happen is at that point update a database field to set the user
logged on status to 1. Everything to that point is fine. I am
getting stuck at updating the databse when the users session ends.
Before the session ends I would like to update the db field for the
user and set the logged on status to 0.
I haven't used application.cfc before. I have been messing around but nothing is working. Here is a copy of my application.cfc file. If anyone has any idea on how to run a query onsessionend and update a db I would appreciate it.
<cfcomponent output="false">
<cfset this.name = "test">
<cfset this.applicationTimeout = createTimeSpan(0,2,0,0)>
<cfset this.clientManagement = true>
<cfset this.clientStorage = "registry">
<cfset this.loginStorage = "session">
<cfset this.sessionManagement = true>
<cfset this.sessionTimeout = createTimeSpan(0,0,0,30)>
<cfset this.setClientCookies = true>
<cfset this.setDomainCookies = false>
<cfset this.scriptProtect = false>
<cffunction name="onApplicationStart" returnType="boolean" output="false">
<cfset application.dsn = "dsn">
</cffunction>
<cffunction name="onSessionStart" returnType="void" output="false">
<cfargument name="sessionScope" type="struct" required="true">
<cfargument name="appScope" type="struct" required="false">
</cffunction>
<cffunction name="onSessionEnd" returnType="void" output="false">
<cfargument name="sessionScope" type="struct" required="true">
<cfargument name="appScope" type="struct" required="false">
<!--- Update Logged On Status --->
<cfquery datasource="dsn">
UPDATE LoginNew
SET loggedin = '0'
WHERE username = '#session.loginname#'
</cfquery>
</cffunction>
</cfcomponent>
I haven't used application.cfc before. I have been messing around but nothing is working. Here is a copy of my application.cfc file. If anyone has any idea on how to run a query onsessionend and update a db I would appreciate it.
<cfcomponent output="false">
<cfset this.name = "test">
<cfset this.applicationTimeout = createTimeSpan(0,2,0,0)>
<cfset this.clientManagement = true>
<cfset this.clientStorage = "registry">
<cfset this.loginStorage = "session">
<cfset this.sessionManagement = true>
<cfset this.sessionTimeout = createTimeSpan(0,0,0,30)>
<cfset this.setClientCookies = true>
<cfset this.setDomainCookies = false>
<cfset this.scriptProtect = false>
<cffunction name="onApplicationStart" returnType="boolean" output="false">
<cfset application.dsn = "dsn">
</cffunction>
<cffunction name="onSessionStart" returnType="void" output="false">
<cfargument name="sessionScope" type="struct" required="true">
<cfargument name="appScope" type="struct" required="false">
</cffunction>
<cffunction name="onSessionEnd" returnType="void" output="false">
<cfargument name="sessionScope" type="struct" required="true">
<cfargument name="appScope" type="struct" required="false">
<!--- Update Logged On Status --->
<cfquery datasource="dsn">
UPDATE LoginNew
SET loggedin = '0'
WHERE username = '#session.loginname#'
</cfquery>
</cffunction>
</cfcomponent>
