Hi,
Is it possible to make a session last until the user logs out? I am currently using sessions with a site, but the session seems to run out pretty quickly and the user is forced to login again.
Thanks for any help, ~Oni.
Set the session.cookie_lifetime to 0 (zero) which maintains the session cookie until the browser is closed, and set the session.gc_maxlifetime to a large number of seconds (e.g. 14400 for 4 hours).
Thanks NogDog, but how do I fit this into the code I use when logging in:
session_start(); $_SESSION['user_id'] = $row['user_id']; $_SESSION['authenticated'] = $row['username'];
Your options are:
Modify the server settings in the php.ini file.
Set them on a per-directory basis via a .htaccess file (if on Apache)
Set them in each script, e.g.:
<?php // these must be done before session_start(): session_set_cookie_params(0); // session cookie time-out ini_set('session.gc_maxlifetime', 14400); // garbage-collection time in seconds // now you can start session: session_start();
Since these setting would have to be done in each file, it would probably be a good idea to put them into a separate include file (perhaps along with any other related functionality that needs to be run at the start of each page). Then you just need to include that file, probably using [man]require_once[/man].
Works perfect!! Thanks again NogDog 🙂