Jump to content

Recommended Posts

I have a form that is very long.  Sometimes the logged-in user will spend over 20 minutes on this screen and then when they hit submit, the session has already expired and they are redirected to the login screen and anything on that form is lost.

Is there a way to reset the session timeout to zero everytime they either click the screen with the mouse, or type something into a form field (without submitting the form)?  Not sure if this would only work with javascript or if there is php code that I would put in the beginning of the action.php that looks for whether the session has timed out and if so, add the form contents to the database first before logging them out?  A php solution like that would be preferable to a javascript one.

But also if the sessiopn has already expired, then the action.php script would be less secure if I put the code there because then anyone not logged in could use that page so that's probably not the solution.  Best solution would be to reset the session timer whenever they click ont he screen or start typing in the form.

You can't do it with PHP because PHP doesn't interface with the client.

 

But you can run an AJAX request every X minutes. With jQuery:

$(function(){
// set interval for 5 minutes
setInterval(function(){
	$.ajax({url: "keep-alive.php"});
}, 300000);
});

You could just set session.gc_maxlifetime to a longer reasonable value. The purpose of session.gc_maxlifetime is to delete old session data files, not to prevent users from actually using your pages that rely on session variables.

You could just set session.gc_maxlifetime to a longer reasonable value. The purpose of session.gc_maxlifetime is to delete old session data files, not to prevent users from actually using your pages that rely on session variables.

No this won't solve the problem.  If that longer time expires and the user finally presses submit, the for data will not get processed because the user's session will have expired and they will just getr redirected to the login screen.

You can't do it with PHP because PHP doesn't interface with the client.

 

But you can run an AJAX request every X minutes. With jQuery:

$(function(){
// set interval for 5 minutes
setInterval(function(){
	$.ajax({url: "keep-alive.php"});
}, 300000);
});

 

Where do I put that code?  I put jquery in the jquery folder. do I put this in the body?

<script type="text/javascript">
$(function(){
// set interval for 5 minutes
setInterval(function(){
	$.ajax({url: "keep-alive.php"});
}, 300000);
});
</script>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.