Session timeout countdown

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

eddparsons
Ebase User
Posts: 53
Joined: Wed Jan 02, 2013 4:23 pm
Location: Lyndhurst, Hampshire
Contact:

Session timeout countdown

#1

Postby eddparsons » Fri Nov 08, 2019 10:18 am

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.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

Re: Session timeout countdown

#2

Postby Jon » Mon Nov 11, 2019 9:05 am

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
0 x

eddparsons
Ebase User
Posts: 53
Joined: Wed Jan 02, 2013 4:23 pm
Location: Lyndhurst, Hampshire
Contact:

Re: Session timeout countdown

#3

Postby eddparsons » Wed Nov 13, 2019 10:57 am

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
0 x


Who is online

Users browsing this forum: Google [Bot] and 17 guests