0

I have tried a lot of solutions to prevent sessions expiring, but no onw has worked, the last solution was to set

session.gc_maxlifetime = 0
session.gc_probability = 0

But it doesnt work, any other idea to prevent the session expiring?

Fernando Santiago
  • 2,128
  • 10
  • 44
  • 75
  • check that your system doesn't have an external cron/scheduled job that nukes the session files anyways. – Marc B Sep 02 '14 at 19:47
  • `session.gc_maxlifetime = 60 * 60 * 24 * 365;` ? – cmorrissey Sep 02 '14 at 19:51
  • I think yo have to write your own session handling. http://php.net/manual/en/function.session-set-save-handler.php – bitWorking Sep 02 '14 at 19:52
  • but what are you really trying to do? a "remember me" function? – bitWorking Sep 02 '14 at 19:58
  • @bitWorking i have developed a mobile app, the problem is that the users never exits the app only send it to the background, so when they open it again the session is expired and they have to redo the login... – Fernando Santiago Sep 02 '14 at 20:00
  • A mobile app with PHP..interesting. What OS? Probably a infinite session time will not help, because the users get another session if the app wakes up. So using a cookie would help. Search for "remember me". http://stackoverflow.com/questions/3128985/php-loginsystem-remember-me – bitWorking Sep 02 '14 at 20:06
  • I mean, the mobile app is for andorid and ios, but they talk to a web service, this web service verifies if the user is authenticated or not. – Fernando Santiago Sep 02 '14 at 20:11
  • Ok, then it seems to be more a problem with your app programming. You have to cache the session id and make sure you send it with every request. Normally an api is stateless an does not work with sessions. But perhaps this helps: http://stackoverflow.com/a/6054828/1948627. – bitWorking Sep 02 '14 at 20:26

1 Answers1

0

It is a bad idea to do that, but to answer the question ... you can override the default session handler with a custom one and have it ignore the GC calls:

class NoGCSessionHandler extends SessionHandler {

    public function gc($maxlifetime)
    {
        return true;
    }

}

session_set_save_handler(new NoGCSessionHandler());
Narf
  • 14,600
  • 3
  • 37
  • 66