×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Session Management

Logging out by session time limit by webmigit
Posted: 17 May 04

I run a system somewhat like online banking.. And the staff loved remaining logged in.. However the users, who had balances with us, did not..

So I wrote what many developers have written and is really nothing special.. A session timeout script.

--- Before you read this, I suggest you read Glowball's FAQ232-1166 and my FAQ232-1926 both dealing with CFLOCK. ---

The first step is setting your variable.. I'm going to assume you use sessions, you could use cookies and do the same thing here.

Wherever you set your member variables add this

CODE

<cfset session.logtime=Now()>

or for you cookie people

CODE

<cfcookie expires="7" name="logtime" value="#Now()#">

You'll want to update this on each page so that its not 15 minutes from login, but 15 minutes from last activity. (Which of course means that if for some reason you wanted to limit total login time, you just wouldn't do this next step).

CODE

<cfset session.logtime=Now()>

or for you cookie people

CODE

<cfcookie expires="7" name="logtime" value="#Now()#">

Now finally.. in application.cfm or your header file or whatever you like (For those of you that aren't familiar, application.cfm at the beginning of each request meaning that if you type in a cfm page in your url, it will pull it up there but it will not execute it again before calling a custom tag or cfinclude since those are part of the same request).

Change loginidentifier to whatever your identifying variable is.. wheter it be session.logged or cookie.lastloggedin or whatever it is you use.

Change loggedinvalue to whatever value is specified for the loginidentifier variable meaning the user is logged in.

Also note the first parameter of datediff is "n".. "N" means minute because "m" means month.. Consult http://livedocs.macromedia.com/coldfusion/6/CFML_Reference/functions-pt158.htm for more information.

You can change 15 to any amount you like, this is speaking in terms of minutes.

CODE

<cfif loginidentifer eq loggedinvalue>
  <cfif datediff("n",session.logtime,now()) gt 15>
    <Cfset loginidentifier=notloggedinvalu>
    <cflocation user="/homepagefilename.cfm">
  </cfif>
</cfif>

Or for you cookie people

CODE

<cfif cookie.loginidentifer eq loggedinvalue>
  <cfif datediff("n",cookie.logtime,now()) gt 15>
    <cfcookie name="loginidentifier" value="notloggedinvalue" expires="7">
    ...cflocation does not allow cookies in the same document to set, I suggest you use javascript redirect or <Cfabort> or something...
  </cfif>
</cfif>

Back to Adobe FAQ Index
Back to Adobe Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close