Session Timeout fix

143 views Asked by At

I've created a sort of exam site where answers are input, in order to figure out the answers, the open exam page which must be logged into can remain idle for some time.

I tried implementing this line of code to increase session timeout length to an hour:

ini_set('session.gc_maxlifetime', 3600);

though I don't think it has worked for me. Does this have to be done on each page that I have the code:

session_start()

Also what is the convention in ensuring a login session remains open until: - tab close - window close - logout button-press - a new URL is entered in the address bar ?

1

There are 1 answers

0
cjhill On BEST ANSWER

Does this have to be done on each page

Yes. As the PHP manual for ini_set states:

The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.


Alternatively, you could "ping" your server every minute to keep the session alive (such as from an ajax request to a simple PHP script (something as simple as <?php session_start(); ?> will suffice)), or you could control the sessions yourself through a medium such as a database. Chris Shiflett has a good blog post on this.