4
As the title of the question says I would like at a certain time where the user is idle, and so the system destroys the session and automatically redirects to the login page. I know php has the session_cache_expire function() (http://php.net/manual/en/function.session-cache-expire.php). However, from what I understood this time is independent of the user being idle, besides that at the end of the time the session will only be destroyed when the page is requested. I believe that many here have had the unpleasant experience of filling out an extensive form and when sending the Ubmit lose data due to the time spent filling out the form (I had filling in the data for ENEM registration on mobile). I would prefer to use only PHP, but I think it will be necessary to use javascrpit as well. Thanks for your attention.
This example of Enem is dirty programming (and nut programming is what more has, especially in the public thing). A decent system would keep the form data, even the finished session, and allow you to relocate to continue, in a more extreme case. There may be some fool who doesn’t understand PHP and will tell you to increase session time, but would only change the problem of place (besides not being the right way to use session). The ideal is to think about how to store this form, regardless of the session, and allow the user to continue where he left off (this is true for any kind of data, not just for this case).
– Bacco
In other words, it’s great that you’re worrying about it, but there’s no magic recipe that solves it simply. Session is supposed to be an auxiliary tool. Everything that needs to take a long time, can be managed in more complex ways. For example, it is much cleaner to automatically and transparently relocate the user than to shorten the session. In this case the individual cookie and the non-destructive login (accept the form anyway, but ask login to proceed) has less side effects.
– Bacco
About using JS, one way would be for a script to keep renewing the session with PHP, but if in the meantime there is a small connection fault, you might have the problem the same way. Another idea would be to use JS in addition to solving the problem with PHP, you have a local cache of the form filled (and discard after a reasonable time without use, of course, whether in JS or PHP). Whatever path you choose, it will take a little reasoning and whim, but after all, programming is exactly that.
– Bacco