1
My PHP sessions are expiring in a short time (5min), even using session_cache_expire(120), and would need it to be at least 2hours.
I’m using a code similar to this:
session_cache_expire(120);
session_start();
if(!isset($_SESSION['id'])){
header("Location: ../../index.html");
}else{
$id = $_SESSION['id'];
}
In phpinfo() I have the following information:
How long did you want the session to last?
– Bacco
Set fast (short time)? Do you have evidence? How do we know what is actually happening? I don’t remember much more if you can change at runtime in any situation, if you’re in shared hosting it’s likely you can’t. But you should allow a lot more time.
– Maniero
@Bacco, it’s expiring in less than 5 minutes. I’d like you to stay for a couple of hours.
– Tiego Araujo
and how you proved that the problem is the session?
– Bacco
By the code above. I imagine the "if(! isset($SESSION['id']){}" serves exactly that: so when the session(id) variable no longer exists, it redirects to the path file .. /.. /index.html
– Tiego Araujo
Access your application with the developer tools open, go to Application, Storage, Cookies, access your domain, search for the PHPSESSID cookie and check the value in Expires / Max-Age.
– Woss
The value is this: 1969-12-31T23:59:59.000Z, @Andersoncarloswoss
– Tiego Araujo
And what do you conclude with that?
– Woss
Change the session lifetime... From what I searched here, I can use the following command: ini_set('Session.cookie_lifetime', 120*60);
– Tiego Araujo
@Andersoncarloswoss, correct?
– Tiego Araujo
Is there any . htaccess with session settings? I had a case like this, I was set in this file and settings in php files have no effect.
– Marcelo