添加此评论作为一个答案为更好的格式
利应有的信用。如果你添加你的答案,我会删除这个赞成你的答案。
鉴于刚添加到答案中的例子,你做错了。正如Leigh在他的评论中指出的那样,您需要在OnSessionEnd
方法中以不同的方式引用会话范围。
您还缺少OnSessionEnd
方法的参数。
您可能还想确保在尝试使用它们之前定义变量。您的查询中也应该使用<cfqueryparam>
。
把它放在一起,它应该是这个样子:
<cffunction name="OnSessionEnd" access="public" returntype="void" output="false">
<cfargument name="SessionScope" type="struct" required="true" />
<cfargument name="ApplicationScope" type="struct" required="false" default="#StructNew()#" />
<cfif StructKeyExists(ARGUMENTS.ApplicationScope,"datasource") AND StructKeyExists(ARGUMENTS.SessionScope,"user_id")>
<cfquery name="local.logout" datasource="#ARGUMENTS.ApplicationScope.datasource#">
update user
set logout_date = CURRENT_TIMESTAMP
where profile_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#ARGUMENTS.SessionScope.user_id#" />
</cfquery>
<cfelse>
<!--- variables are not defined, do something else here? --->
</cfif>
<cfreturn />
</cffunction>
而且,请求范围并不在此方法中使用,因为它不是由一个请求来调用。
您可以在[OnSessionStart](https://helpx.adobe.com/coldfusion/cfml-reference/application-cfc-reference/onsessionstart.html)和[OnSessionEnd](https://)中捕获该类信息helpx.adobe.com/coldfusion/cfml-reference/application-cfc-reference/onsessionend.html)。 – Leigh
一旦会话死了,你到了OnSessionEnd我会在哪里获得用户ID以便能够记录他们现在注销?什么范围仍然可用? –
由于会话超时,onSessionEnd将被触发。任何会话变量都将存在,直到该函数完成执行。 –