I have been looking all day for a PHP or JavaScript solution to do this.
I would like to alert the user their session is about to time out (popup), ability to extend the session time.
Here is a visual if you need one on this page
EDIT:
jQuery is the framework if that helps
It's relatively easy:
Build a JavaScript timer that fires in (session lifetime - 5 min) minutes using setTimeout
Have the setTimeout
function show a confirmation dialog, e.g. using jQuery UI Dialog
If the user wants to prolong the session, make an Ajax request to an PHP file. If the file uses sessions, this will work to "touch" the session's lifetime
After making the request, set another setTimeout
that will fire when the session is about to expire again.
I would suggest a different approach; just refresh the session for the user anyway. Most unwanted session-deaths happen because of
and with a confirmation dialog, the session would already by dead by the time your user comes back - adding only confusion.
Instead:
var refresh_session = function () {
$.get("/refresh_session.php");
},
fifteen_minutes = 15 * 60 * 1000;
setInterval(refresh_session, fifteen_minutes);
--> happy users! :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With