I have a requirement like, if user closes browser then upon the next access of the site user should be asked to login again: I have written the following code in .htaccess file which is working fine:
<IfModule mod_php5.c>
#Session timeout
php_value session.cookie_lifetime 1200
php_value session.gc_maxlifetime 1200
</IfModule>
I am excited to know am I doing the correct thing, or is there any other best way to do this?
Set the session cookie parameters before you start your session.
session_set_cookie_params(0);
session_start();
Zero means "until the browser is closed".
This solution would be my personal "best" way of doing it, because you can control it per PHP-script, instead of site-wide. Also, it is clear from the PHP code, instead of relying on server-dependent settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With