fix session

This commit is contained in:
Eric Espie
2026-04-16 13:49:36 +02:00
parent 751ad846a4
commit 9f15385545

View File

@@ -23,8 +23,6 @@ class Session
/** @var bool */ /** @var bool */
protected static $bIsInitialized = false; protected static $bIsInitialized = false;
/** @var bool */ /** @var bool */
protected static $bSessionStarted = false;
/** @var bool */
public static $bAllowCLI = false; public static $bAllowCLI = false;
public static function Start() public static function Start()
@@ -36,7 +34,6 @@ class Session
if (session_status() === PHP_SESSION_ACTIVE) { if (session_status() === PHP_SESSION_ACTIVE) {
// Session already started // Session already started
self::$bIsInitialized = true; self::$bIsInitialized = true;
self::$bSessionStarted = true;
self::$iSessionId = session_id(); self::$iSessionId = session_id();
return; return;
} }
@@ -47,16 +44,14 @@ class Session
} }
self::$bIsInitialized = true; self::$bIsInitialized = true;
if (!self::$bSessionStarted) {
if (!is_null(self::$iSessionId)) { if (!is_null(self::$iSessionId)) {
if (session_id(self::$iSessionId) === false) { if (session_id(self::$iSessionId) === false) {
session_regenerate_id(true); session_regenerate_id(true);
} }
} }
self::$bSessionStarted = session_start(); session_start();
self::$iSessionId = session_id(); self::$iSessionId = session_id();
} }
}
public static function RegenerateId($bDeleteOldSession = false) public static function RegenerateId($bDeleteOldSession = false)
{ {
@@ -65,10 +60,10 @@ class Session
} }
session_regenerate_id($bDeleteOldSession); session_regenerate_id($bDeleteOldSession);
if (self::$bSessionStarted) { if (session_status() === PHP_SESSION_ACTIVE) {
self::WriteClose(); self::WriteClose();
} }
self::$bSessionStarted = session_start(); session_start();
self::$iSessionId = session_id(); self::$iSessionId = session_id();
} }
@@ -78,9 +73,8 @@ class Session
return; return;
} }
if (self::$bSessionStarted) { if (session_status() === PHP_SESSION_ACTIVE) {
session_write_close(); session_write_close();
self::$bSessionStarted = false;
} }
} }
@@ -103,7 +97,7 @@ class Session
$sSessionVar = &$sSessionVar[$key]; $sSessionVar = &$sSessionVar[$key];
} }
$sSessionVar = $value; $sSessionVar = $value;
if (!self::$bSessionStarted) { if (session_status() !== PHP_SESSION_ACTIVE) {
self::Start(); self::Start();
$_SESSION = $aSession; $_SESSION = $aSession;
self::WriteClose(); self::WriteClose();
@@ -131,7 +125,7 @@ class Session
$sPrevKey = $sKey; $sPrevKey = $sKey;
} }
} }
if (!self::$bSessionStarted) { if (session_status() !== PHP_SESSION_ACTIVE) {
self::Start(); self::Start();
unset($sSessionVar[$sKey]); unset($sSessionVar[$sKey]);
$_SESSION = $aSession; $_SESSION = $aSession;