Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

session timeout alert

New Here ,
Sep 02, 2009 Sep 02, 2009

Anyone know of a way to monitor a session with java and have an alert when the session is close to ending giving the person browsing an opportuntiy to keep the session alive. My bank does this after 15 minutes. I am currently setting session.DateInitialized in the onSessionStart function in Application.cfc. I suppose I need a java script to call that every minute and when there are 5 minutes left of a 60 minute session it opens and alert box. Anyone have one of these handy? 😉

3.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 02, 2009 Sep 02, 2009

Most often this is just done with a JavaScript timeout function set to a similar length of time as the session time out on the server.  Google search Javascript timout and you will find dozens of such scripts.

The problem is that with normal HTTP comunications the server can not push a new message to the client in the future.  It can only wait and respond to a request from the client (pull).  So the idea is that the JavaScript timout function will either display the message itself, or send a request (with AJAX if you would like it done in the background) to the server to get the message or whatever you would like it to do.

If you use technologies that go beyond normal browser HTTP requests and responses, then you may be able to have the server push messages to registerd clients that are listening for them.  FLEX and AIR are capable of this type of push and pull comunications and work easily with ColdFusion.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2009 Sep 02, 2009

I found a script and tewaked it. Thanks again Ian.

I added this in an include in all the pages on the members side. Pretty self explanitory,

The alert fires after 58 minutes (my session is 60).

If they click OK before the session dies, it sends them to the members homepage.

Would have liked to send them back to the page they were on but it could have been an action page (add to cart, delete item etc)

<SCRIPT LANGUAGE="JavaScript">

function autolog() {

alert('Your session is going to timeout in 60 seconds. Click OK to stay logged in.');

location.href = "shop.cfm";

}

setTimeout('autolog()',(1000*60*58));

</SCRIPT>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 02, 2009 Sep 02, 2009
LATEST

Depending on your needs and desired requirements.

Instead of sending them to the home page if they click OK, you could fire off a simple XMLHttpRequest() object [http://www.w3schools.com/XML/xml_http.asp] call that reqeusts a ColdFusion 'heartbeat' page.  Which is really just a simple CFML page that belongs to the same applicaiton/session to which the user belongs.  This will refresh the session time out out counter on ColdFusion.  Of course you would also want to reset the timeout counter in the JavaScript as well.

Sometimes that type of behavior is desireable, sometimes it is not.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources