odan / slim4-skeleton

A Slim 4 Skeleton
https://odan.github.io/slim4-skeleton/
MIT License
439 stars 80 forks source link

PHP Session timeout #32

Closed nmatias closed 3 years ago

nmatias commented 3 years ago

How do I expire a PHP session after 30 minutes for example? I try this to add this values in the config/defaults.php but it doesn't work:

// Session $settings['session'] = [ 'name' => 'webapp', 'cache_expire' => 0, 'gc_maxlifetime' => 3600, 'cookie_lifetime' => 604800 ];

Thanks, Nelson Matias

odan commented 3 years ago

According to the documentation the cookie_lifetime is in seconds and should be 60 * 30 = 1800 to expire the cookie after 30 minutes. A cookie lifetime of 0 means the cookie expires when the browser is closed.

I would try exactly this here first:

// Session
$settings['session'] = [
    'name' => 'webapp',
    'cookie_lifetime' => 1800,
];

Don't define any gc_* settings to use the default values of the system. If my example from above is still not working try to configure the garbage collector settings manually. You can play with these settings by passing gc_probability, gc_divisor and gc_maxlifetime. Read more

nmatias commented 3 years ago

Thanks Daniel,

Work perfectly. I have already say that but the work and support you give to the community is to be commended.

Thanks a lot!!!