Controlling sessions on a shared server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xtrent
Forum Newbie
Posts: 1
Joined: Thu Sep 01, 2011 3:45 pm

Controlling sessions on a shared server

Post 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
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Controlling sessions on a shared server

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Controlling sessions on a shared server

Post 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 :)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply