lexeme
lexeme

Reputation: 2973

Running a long term session and garbage collection in PHP

What I want is to be able to save a session variable for 12 hours so user don't need to re-log in.

I'm using something like this:

if(ini_get('session.gc_maxlifetime') !== 3600*12) {
    ini_set('session.gc_maxlifetime', 3600*12);
}
if(ini_get('session.cookie_lifetime') !== 3600*12) {
    ini_set('session.cookie_lifetime', 3600*12);
}

session_start();    

And I've echoed the vars and they all are set properly. But as long as browser gets closed session gets destroyed and user must log in.

I've read recently (but can't find the resource now) that one should change the location folder for long running session cookies because of garbage collection.

Where/How do I configure that?

Thanks!

Upvotes: 1

Views: 188

Answers (1)

Eugene
Eugene

Reputation: 3375

This code looks ok. You should check PHPSESSID cookie on the client side first to ensure that it is really set to expire in +12 hours. Since you are saying that "as long as browser gets closed session gets destroyed and user must log in" the cookie is not set to expire in +12 hours. Are you starting the session after you set session.* variables?

Upvotes: 1

Related Questions