PHP session expiring fast

Asked

Viewed 313 times

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:

inserir a descrição da imagem aqui

  • How long did you want the session to last?

  • 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.

  • @Bacco, it’s expiring in less than 5 minutes. I’d like you to stay for a couple of hours.

  • and how you proved that the problem is the session?

  • 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

  • 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.

  • The value is this: 1969-12-31T23:59:59.000Z, @Andersoncarloswoss

  • And what do you conclude with that?

  • Change the session lifetime... From what I searched here, I can use the following command: ini_set('Session.cookie_lifetime', 120*60);

  • @Andersoncarloswoss, correct?

  • 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.

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.