diff --git a/core/userrights.class.inc.php b/core/userrights.class.inc.php index 2ef9b623b..2edd33a04 100644 --- a/core/userrights.class.inc.php +++ b/core/userrights.class.inc.php @@ -1838,6 +1838,7 @@ class UserRights self::$m_aAdmins = array(); self::$m_aPortalUsers = array(); } + Session::FlushSession(); self::_ResetSessionCache(); if (self::$m_oAddOn) { @@ -1936,7 +1937,7 @@ class UserRights // The bug has been fixed in PHP 7.2, but in case session_regenerate_id() // fails we just silently ignore the error and keep the same session id... $old_error_handler = set_error_handler(array(__CLASS__, 'VoidErrorHandler')); - session_regenerate_id(true); + Session::RegenerateId(true); if ($old_error_handler !== null) { set_error_handler($old_error_handler); } diff --git a/sources/application/Helper/Session.php b/sources/application/Helper/Session.php index 9a90ca5b4..512f47dcd 100644 --- a/sources/application/Helper/Session.php +++ b/sources/application/Helper/Session.php @@ -7,6 +7,8 @@ namespace Combodo\iTop\Application\Helper; +use utils; + /** * Session management * Allow early session close to have multiple ajax calls in parallel @@ -25,14 +27,19 @@ class Session public static function Start() { + if (utils::IsModeCLI()) { + return; + } + if (!self::$bIsInitialized) { session_name('itop-'.md5(APPROOT)); } + self::$bIsInitialized = true; if (!self::$bSessionStarted) { if (!is_null(self::$iSessionId)) { if (session_id(self::$iSessionId) === false) { - session_regenerate_id(); + session_regenerate_id(true); } } self::$bSessionStarted = session_start(); @@ -40,8 +47,36 @@ class Session } } + public static function FlushSession() + { + if (utils::IsModeCLI()) { + return; + } + + if (!is_null(self::$iSessionId)) { + self::$bIsInitialized = false; + self::$bSessionStarted = false; + self::Start(); + } + } + + public static function RegenerateId($bDeleteOldSession = false) + { + if (utils::IsModeCLI()) { + return; + } + + session_regenerate_id($bDeleteOldSession); + self::$bSessionStarted = session_start(); + self::$iSessionId = session_id(); + } + public static function WriteClose() { + if (utils::IsModeCLI()) { + return; + } + if (self::$bSessionStarted) { session_write_close(); self::$bSessionStarted = false;