Page 1 of 1

Controlling sessions on a shared server

Posted: Thu Sep 01, 2011 4:07 pm
by xtrent
Hello,

Hoping someone might have some insight into this hopefully easy-to-answer question. I am relatively new to PHP, but come from a programming background.

I am running a website hosted on a 1and1(.com) shared server, and I find that session data sometimes persists for hours and hours, but other times is lost within minutes of creating it. This may pose a problem for my customers who will log into their accounts, because there is no certainty about how long their session will remain active. If their session dies while they are filling out a form, they may be directed back to the login page after they hit Submit, which is a bit of an inconvenience. They should only have to log in once, not several times.

Is this happening because the shared server has some kind of global session garbage collector that runs at intervals (random ones, as far as I'm concerned), dumping all active sessions? And if so, is there any way to set a config flag that says please don't kill mine? Or, is it a client-side (browser) issue, or coding practices.

If this can only be resolved by moving to a dedicated server, I may do so.

Thanks

Re: Controlling sessions on a shared server

Posted: Thu Sep 01, 2011 11:56 pm
by Eric!
You can manage users via a database. Create your own session id for the user, login time, etc. If data or requests are made after the expiration time you can re-log them in.

Re: Controlling sessions on a shared server

Posted: Fri Sep 02, 2011 2:53 am
by VladSun
Or just create a directory (Apache user writable) and change your session files save path: http://php.net/manual/en/function.session-save-path.php
The server session garbage collector won't find them there :)