asked on
<CFAPPLICATION name="myapp"
sessionmanagement="Yes"
setclientcookies="Yes"
sessiontimeout="#CreateTimeSpan(0, 3, 0, 0)#">
ASKER
ASKER
ASKER
Application.cfc onRequest
----------------------------------------
<!--- Begin Who's Online section --->
<!--- determines timeout to heck if user still is active.
set to 0 will check on each page load and will cause list to change a lot as people "timeout"
while viewing or working on pages
set to 10 minutes will give a more general idea of activity.
remember that activity timeout and session timeout may be different.
--->
<cfset ActivityTimeout = 0>
<!--- if we still have a session id but have been cleared from the struct reset the struct
this would be due to having an activity online timeout which is shorter than
your session timeout. --->
<!-- check if session exists -->
<cfif structKeyExists(session,"whosOnFirst")>
<!-- check if key in who's online exists -->
<cfif NOT StructKeyExists(Application.UsersInfo, session.whosOnFirst)>
<cfset temp = StructInsert(Application.UsersInfo, session.whosOnFirst, now())>
</cfif>
</cfif>
<cfloop collection="#Application.UsersInfo#" item="uName">
<!--- if the struct matches the session id then it's us so update our activity time --->
<cfif structKeyExists(session,"whosOnFirst")>
<cfif uName eq session.whosOnFirst>
<cfset user_cfid = uName>
<cfset user_time = Now()>
<cfset temp = StructUpdate(Application.UsersInfo, user_cfid, user_time)>
</cfif>
</cfif>
<!--- look for values in the struct which are larger than ActivityTimeout
and delete them as their timeout period will have expired. --->
<cfif Evaluate(DateDiff("n", StructFind(Application.UsersInfo, uName), Now())) GT ActivityTimeout>
<cfset StructDelete(Application.UsersInfo, uName)>
</cfif>
</cfloop>
<!--- end Who's Online section --->
Application.cfc onRequest in your successful login section
----------------------------------------
<!--- begin Who's Online section --->
<cfparam name="session.whosOnFirst" default="">
<!--- Test for existence of UserInfo and create if necessary --->
<cflock timeout="15" scope="APPLICATION" type="EXCLUSIVE">
<cfif NOT isDefined("Application.UsersInfo")>
<cfset Application.UsersInfo = StructNew()>
</cfif>
</cflock>
<cfif isDefined('form.userName')>
<!--- create new user info for the struct --->
<cflock name="#CreateUUID()#" timeout="15" type="EXCLUSIVE">
<cfset user_cfid = Evaluate(CFID) & "," & form.userName>
<cfset user_time = Now()>
</cflock>
<!--- set a session id so we can use it to verify that this session is still active in application.cfm --->
<cfset session.whosOnFirst = user_cfid>
<cflock scope="APPLICATION" type="EXCLUSIVE" timeout="15">
<!--- If the user does not exist in the struct, insert it --->
<cfif NOT StructKeyExists(Application.UsersInfo, user_cfid)>
<cfset temp = StructInsert(Application.UsersInfo, user_cfid, user_time)>
</cfif>
</cflock>
</cfif>
<!--- end Who's Online section --->
whosOnFirst.cfm
----------------------------------------------
<div style="padding:5px;">
<cflock scope="APPLICATION" type="EXCLUSIVE" timeout="10">
<cfoutput>
Users Online : #StructCount(Application.UsersInfo)#<br>
<cfloop collection="#Application.UsersInfo#" item="uName">
<cfif Uname eq session.whosOnFirst>
<div style="font-weight:bold;border-top:1px dashed;border-bottom:1px dashed;">#listlast(UCASE(Uname))#</div><!--- this is me --->
<cfelse>
<div>#listlast(UCASE(Uname))# <br>
<span style="font-size:.7em;">
Last Activity : #timeformat(structfind(Application.UsersInfo,uname), "hh:mm:ss")#
</span></div>
</cfif>
</cfloop>
</cfoutput>
</cflock>
</div>
ASKER
ASKER
ColdFusion is a server-side rapid application development platform originally created by Allaire and now sold by Adobe, implementing the dynamic general purpose CFML programming language. The term ColdFusion is sometimes colloquially used to refer to the CFML language (Cold Fusion Markup Language), but can also include discussions of the server software implementation. ColdFusion runs using a customised version of Apache Tomcat. Earlier versions are bundled with JRun.
TRUSTED BY
The only way to -test- for a session timeout is to validate whether the session variable(s) still exist when the client reloads the page.
<cfif session.somevar eq "">
Your session has timed out. PLease logon again
</cfelse>
normal page
</cfif>
or you can use cflocation
<cfif session.somevar eq "">
<cflocation url-"sessionTimedOut.cfm">
</cfif>
session timeout -is- defined by client access of a particular session or as you call idle timeout.If you have session timeout set to 20 minutes and a client accesses the page once every 10 minutes, the session will never timeout (until the application times out)