Restore feature to manage timeout (when garbage is done at page access)

This commit is contained in:
Laurent Destailleur 2026-03-25 23:36:43 +01:00
parent b87f8389ea
commit 9d2ac941b7
4 changed files with 4 additions and 6 deletions

View file

@ -80,7 +80,7 @@ if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
$res1 = dolibarr_set_const($db, "MAIN_APPLICATION_TITLE", GETPOST("MAIN_APPLICATION_TITLE", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
}
if (GETPOSTISSET('MAIN_SESSION_TIMEOUT')) {
$res2 = dolibarr_set_const($db, "MAIN_SESSION_TIMEOUT", GETPOST("MAIN_SESSION_TIMEOUT", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
$res2 = dolibarr_set_const($db, "MAIN_SESSION_TIMEOUT", max(120, min(3600 * 24, GETPOSTINT("MAIN_SESSION_TIMEOUT"))), 'chaine', 0, '', $conf->entity); // Between 120 and 86400
}
if (GETPOSTISSET('MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT')) {
$res3 = dolibarr_set_const($db, "MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", GETPOST("MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 'alphanohtml'), 'int', 0, '', $conf->entity);

View file

@ -133,7 +133,7 @@ function dolSessionWrite($sess_id, $val)
if (empty($sessionidfound)) {
if ((int) ini_get('session.gc_probability') == 0) {
// dolSessionGC will be never called
$max_lifetime = max(getDolGlobalInt('MAIN_SESSION_TIMEOUT'), (int) ini_get('session.gc_maxlifetime'));
$max_lifetime = min(3600 * 24, max(getDolGlobalInt('MAIN_SESSION_TIMEOUT'), (int) ini_get('session.gc_maxlifetime')));
$delete_query = "DELETE FROM ".MAIN_DB_PREFIX."session";
$delete_query .= " WHERE last_accessed < '".$dbsession->idate($time_stamp - $max_lifetime)."'";
$dbsession->query($delete_query);

View file

@ -202,9 +202,7 @@ if (!function_exists('dol_loginfunction')) {
$sessiontimeout = 'DOLSESSTIMEOUT_'.$prefix;
if (getDolGlobalString('MAIN_SESSION_TIMEOUT')) {
if (session_status() != PHP_SESSION_ACTIVE) {
dolSetCookie($sessiontimeout, getDolGlobalString('MAIN_SESSION_TIMEOUT'), 0);
}
dolSetCookie($sessiontimeout, getDolGlobalString('MAIN_SESSION_TIMEOUT'), 0);
}
if (GETPOST('urlfrom', 'alpha')) {

View file

@ -113,7 +113,7 @@ $prefix = dol_getprefix('');
$sessionname = 'DOLSESSID_'.$prefix;
$sessiontimeout = 'DOLSESSTIMEOUT_'.$prefix;
if (!empty($_COOKIE[$sessiontimeout])) {
ini_set('session.gc_maxlifetime', $_COOKIE[$sessiontimeout]);
ini_set('session.gc_maxlifetime', max(120, min(3600 * 24, (int) $_COOKIE[$sessiontimeout]))); // Between 120 and 86400
}
// This create lock, released by session_write_close() or end of page.