dracoblue.net

Avoid session expiration in Webapplications (e.g. PHP)

Some of you may have run into the problem that the default session timeout (about 15 minutes) isn't always useful if your users have to fill a large form with lots of text.

Often you get after those: 'Session timed out' and after login the user has to type all again. To fix that, you can wait for the login and refill the form with the saved data. That is not very handy and quite difficult to implement.

A very handy and fast fix for this session timeout is, that you query the server every minute once to keep the session alive without requiring the user to reload the page. I found out that that soloution is used even in SMF, so it seems to be quite common.

So just add the following lines to an extra page or the start of your index-file.

session_start(); if (isset($_GET['sessionfix']))Â? exit;

And now add the magic javascript, which updates that in the template or html file.

That's it!

In articles, open source, php by
@ 27 Feb 2008, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About