Has anyone implemented a countdown to session timeout in an form that they can share?
This is to display on the page to warn a user their session is about to expire.
Session timeout countdown
Moderators: Jon, Steve, Ian, Dave
-
- Ebase User
- Posts: 53
- Joined: Wed Jan 02, 2013 4:23 pm
- Location: Lyndhurst, Hampshire
- Contact:
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
Re: Session timeout countdown
Here's an outline of how it might be done.
Use the setInterval() function on the browser to run a check at fixed intervals - say once a minute.
Call a function on the server using $eb.executeFunction("getRemainingTimeoutTime").
The server function returns the remaining time before the session times out. This can be determined something like this (not tested):
function getRemainingTimeoutTime() {
// Get the timeout period in milliseconds
var timeoutInMs = client.httpSession.getMaxInactiveInterval() * 1000;
// Calculate the time when this session will timeout
var timeoutTime = client.httpSession.getLastAccessedTime() + timeoutInMs ;
// Subtract the current time to get the remaining time
var now = new Date();
var timeRemaminingInSeconds = (timeoutTime - now.getTime())/1000;
return timeRemaminingInSeconds;
}
You may also be interested in this post which discusses how to keep sessions alive.
viewtopic.php?f=4&t=823&p=2940
Use the setInterval() function on the browser to run a check at fixed intervals - say once a minute.
Call a function on the server using $eb.executeFunction("getRemainingTimeoutTime").
The server function returns the remaining time before the session times out. This can be determined something like this (not tested):
function getRemainingTimeoutTime() {
// Get the timeout period in milliseconds
var timeoutInMs = client.httpSession.getMaxInactiveInterval() * 1000;
// Calculate the time when this session will timeout
var timeoutTime = client.httpSession.getLastAccessedTime() + timeoutInMs ;
// Subtract the current time to get the remaining time
var now = new Date();
var timeRemaminingInSeconds = (timeoutTime - now.getTime())/1000;
return timeRemaminingInSeconds;
}
You may also be interested in this post which discusses how to keep sessions alive.
viewtopic.php?f=4&t=823&p=2940
0 x
-
- Ebase User
- Posts: 53
- Joined: Wed Jan 02, 2013 4:23 pm
- Location: Lyndhurst, Hampshire
- Contact:
Re: Session timeout countdown
Thanks Jon.
The problem with that is that calling the function resets the client.httpSession.getLastAccessedTime variable, so the session will never time out.
Although both this and the other post you linked will only keep the session alive while the browser is open which is a possibility and simpler than trying to warn of an impending timeout. I will go with this. Thanks again.
Regards,
Edd
The problem with that is that calling the function resets the client.httpSession.getLastAccessedTime variable, so the session will never time out.
Although both this and the other post you linked will only keep the session alive while the browser is open which is a possibility and simpler than trying to warn of an impending timeout. I will go with this. Thanks again.
Regards,
Edd
0 x
Who is online
Users browsing this forum: No registered users and 7 guests