How to show the user when his session will timeout

2,389 views
Skip to first unread message

Thorsten Eilers

unread,
Aug 4, 2012, 2:49:31 AM8/4/12
to cfwh...@googlegroups.com
Morning,
I would like to show my users (guests and users logged in) when their session will timeout.

Is this value stored in a session-var in CF? In which one?

I thought to read this value, output it to javascript and have a javascript counter timing down the remaining time.

What do you think of this. It could be useful for someone filling out a large form, who will be upset if the session timed out before submitting it.

Kym Kovan

unread,
Aug 4, 2012, 3:11:48 AM8/4/12
to cfwh...@googlegroups.com
Afternoon over here :-)

The session timeout counter gets reset to zero on every page request so
the usual way of doing this is to have a js counter showing the
countdown on the page as you suggest but there is no need to read the
counter it always is at zero when the page is processed.

You can also reset the session timeout counter by using ajax, in fact if
you are doing something like on-the-fly-validation via jQuery then the
session timeout is being reset at every field entry or whenever you do
an ajax call so you need to handle that in the page display.


hth,
Kym
> --
> You received this message because you are subscribed to the Google
> Groups "ColdFusion on Wheels" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/cfwheels/-/Oen-m4nC_0sJ.
> To post to this group, send email to cfwh...@googlegroups.com.
> To unsubscribe from this group, send email to
> cfwheels+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/cfwheels?hl=en.

--

Yours,

Kym


Thorsten Eilers

unread,
Aug 4, 2012, 5:05:05 AM8/4/12
to cfwh...@googlegroups.com
That makes sense, Kym. Thanks for your post.

Merritt

unread,
Aug 5, 2012, 3:05:46 AM8/5/12
to cfwh...@googlegroups.com
I suggest you check out this blog post:
http://jehiah.cz/a/extended-operations-on-coldfusion-sessions

I know there is a way to get the time remaining without "touching" the session and resetting it.  Check out the section on getTimeSinceLastAccess() and the rewindlife blog post as well.  Good luck.

-Merritt

Chris Peters

unread,
Aug 6, 2012, 1:41:13 PM8/6/12
to cfwh...@googlegroups.com
The idleTimeout jQuery plugin does a nice job of handling this.

Bonus points if you make it dynamic by basing it on your application's this.SessionTimeout.

// events/onrequeststart.cfm
request.sessionTimeout = this.SessionTimeout * 1000;

// Bottom of views/layout.cfm
#hiddenFieldTag(id="session-timeout", name="sessionTimeout", value=request.sessionTimeout)#

// Example jQuery code
$(document).idleTimeout({
inactivity: $("#session-timeout").val() - 300000, // Show popup 5 minutes before session timeout
noconfirm: 300000, // Show "no confirm" box for 5 minutes
sessionAlive: 1800000, // Keep session alive on server every 30 minutes just to be safe
alive_url: "/keep-alive",
logout_url: "/sessions/timeout",
redirect_url: "/login"
});


--

Thorsten Eilers

unread,
Aug 7, 2012, 11:53:03 AM8/7/12
to cfwh...@googlegroups.com

Thanks Chris. Your suggested plugin look rather sophisticated.
Thorsten
Reply all
Reply to author
Forward
0 new messages