From 28cd6170e1166daa5e13d3a0ef88f0ac31e19050 Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 13:32:02 -0700 Subject: [PATCH 01/25] Update namespace --- src/Exception/ExceptionInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 9e769d6..aaf1864 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -23,7 +23,7 @@ * SOFTWARE. */ -namespace Omatamix\SessionLock\Exception; +namespace Cytrenna\SessionLock\Exception; use Throwable; From c78126351fda3291afc8694ae61d6215bb68a4a1 Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 13:32:44 -0700 Subject: [PATCH 02/25] Update namespace --- src/Exception/InvalidFingerprintException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Exception/InvalidFingerprintException.php b/src/Exception/InvalidFingerprintException.php index 0bcd18a..5f119de 100644 --- a/src/Exception/InvalidFingerprintException.php +++ b/src/Exception/InvalidFingerprintException.php @@ -23,7 +23,7 @@ * SOFTWARE. */ -namespace Omatamix\SessionLock\Exception; +namespace Cytrenna\Session\Exception; use Exception; From 577e72ce2c9249c8637d8a464f93a958ab6e5f11 Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 13:33:03 -0700 Subject: [PATCH 03/25] Update namespace --- src/Exception/ExceptionInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index aaf1864..1329a73 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -23,7 +23,7 @@ * SOFTWARE. */ -namespace Cytrenna\SessionLock\Exception; +namespace Cytrenna\Session\Exception; use Throwable; From 34c5f1c5c911f0f9386fc792be479cc91d75a3a4 Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 13:35:56 -0700 Subject: [PATCH 04/25] Create SessionClosedException --- src/Exception/SessionClosedException.php | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/Exception/SessionClosedException.php diff --git a/src/Exception/SessionClosedException.php b/src/Exception/SessionClosedException.php new file mode 100644 index 0000000..71a35d1 --- /dev/null +++ b/src/Exception/SessionClosedException.php @@ -0,0 +1,35 @@ + Date: Wed, 6 Aug 2025 13:37:20 -0700 Subject: [PATCH 05/25] Create SessionRunningException --- src/Exception/SessionRunningException.php | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/Exception/SessionRunningException.php diff --git a/src/Exception/SessionRunningException.php b/src/Exception/SessionRunningException.php new file mode 100644 index 0000000..4d19f69 --- /dev/null +++ b/src/Exception/SessionRunningException.php @@ -0,0 +1,35 @@ + Date: Wed, 6 Aug 2025 13:44:27 -0700 Subject: [PATCH 06/25] Update SessionMiddleware --- src/SessionMiddleware.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index 8b13789..f91caca 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -1 +1,33 @@ + Date: Wed, 6 Aug 2025 13:46:38 -0700 Subject: [PATCH 07/25] Update SessionMiddleware.php --- src/SessionMiddleware.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index f91caca..3ddbada 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -30,4 +30,13 @@ */ class SessionMiddleware { + public function handle(callable $next) + { + // Start the session if not already started. + + // Call the next middleware or controller. + $response = $next(); + // Returned the response. + return $response; + } } From f824e1e2e925332e22621dce296e6ff9fb20d611 Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 13:54:33 -0700 Subject: [PATCH 08/25] Update SessionMiddleware --- src/SessionMiddleware.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index 3ddbada..aa3a8f0 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -30,10 +30,25 @@ */ class SessionMiddleware { + /** @var \Cytrenna\Session\SessionManager $sessionManager The session manager. */ + protected SessionManager $session; + + /** + * Construct the session middleware. + * + * @param \Cytrenna\Session\SessionManager $sessionManager The session manager. + * + * @return void Returns nothing. + */ + public function __construct(SessionManager $session) + { + $this->sessionManager = $sessionManager; + } + public function handle(callable $next) { // Start the session if not already started. - + // Call the next middleware or controller. $response = $next(); // Returned the response. From 1b7acefa9fd5344ccaa498cb05660daeb56fc5dc Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 14:00:10 -0700 Subject: [PATCH 09/25] Update SessionMiddleware.php --- src/SessionMiddleware.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index aa3a8f0..54b7ecf 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -48,6 +48,11 @@ public function __construct(SessionManager $session) public function handle(callable $next) { // Start the session if not already started. + try { + $session->isRunning(); + } catch ( $e) { + + } // Call the next middleware or controller. $response = $next(); From b5c2e53436a3feb1583b093925af2d88daf08ead Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 14:02:05 -0700 Subject: [PATCH 10/25] Update SessionMiddleware.php --- src/SessionMiddleware.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index 54b7ecf..a57f44b 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -50,7 +50,8 @@ public function handle(callable $next) // Start the session if not already started. try { $session->isRunning(); - } catch ( $e) { + } catch (SessionClosedException $e) { + $fingerprint = $this->generateUniqueFingerprint(); } From b26a9e7db24fafc7f006df97ba916fa0a3c2f5b7 Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 14:05:06 -0700 Subject: [PATCH 11/25] Update SessionMiddleware --- src/SessionMiddleware.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index a57f44b..3d48fa3 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -51,7 +51,9 @@ public function handle(callable $next) try { $session->isRunning(); } catch (SessionClosedException $e) { - $fingerprint = $this->generateUniqueFingerprint(); + if ($this->fingerprintEnabled()) { + $fingerprint = $this->generateUniqueFingerprint(); + } } From b9c28915816df31b32b6620f7f48775d32ca801b Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 14:30:16 -0700 Subject: [PATCH 12/25] Update SessionMiddleware.php --- src/SessionMiddleware.php | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index 3d48fa3..d878656 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -30,33 +30,47 @@ */ class SessionMiddleware { - /** @var \Cytrenna\Session\SessionManager $sessionManager The session manager. */ + /** @var \Cytrenna\Session\SessionManager $session The session manager. */ protected SessionManager $session; /** * Construct the session middleware. * - * @param \Cytrenna\Session\SessionManager $sessionManager The session manager. + * @param \Cytrenna\Session\SessionManager $session The session manager. * * @return void Returns nothing. */ public function __construct(SessionManager $session) { - $this->sessionManager = $sessionManager; + $this->session = $session; } public function handle(callable $next) { // Start the session if not already started. try { - $session->isRunning(); + $this->session->isRunning(); } catch (SessionClosedException $e) { - if ($this->fingerprintEnabled()) { - $fingerprint = $this->generateUniqueFingerprint(); + // Validate the session fingerprint. + if ($this->session->fingerprintEnabled()) { + $fingerprint = $this->session->generateUniqueFingerprint(); + if ($this->session->has('cytrenna.fingerprint')) { + if (!hash_equals($this->has('cytrenna.fingerprint'), $fingerprint)) { + $this->stopSession(); + throw new InvalidFingerprintException('The fingerprint supplied is invalid.'); + } + } else { + $this->put('cytrenna.fingerprint', $fingerprint); + } } - + // Prevent AJAX requests. + if ($this->session->disallowAjaxRequests()) { + if ($this->isAjaxRequest()) { + throw new AjaxRestrictedException('This application does not allow ajax requests.'); + } + } + // Start the session. } - // Call the next middleware or controller. $response = $next(); // Returned the response. From 6429ad3d8b48eea2865c3dd8fa5db6189fdc2be0 Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 14:35:26 -0700 Subject: [PATCH 13/25] Update SessionMiddleware.php --- src/SessionMiddleware.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index d878656..ddfaf34 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -70,6 +70,7 @@ public function handle(callable $next) } } // Start the session. + $this->session->start(); } // Call the next middleware or controller. $response = $next(); From 81ad72f2b4aba1cc73cbeec0e6ffc9a1c830e40f Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 14:35:52 -0700 Subject: [PATCH 14/25] Update SessionMiddleware.php --- src/SessionMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index ddfaf34..c6eee07 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -65,7 +65,7 @@ public function handle(callable $next) } // Prevent AJAX requests. if ($this->session->disallowAjaxRequests()) { - if ($this->isAjaxRequest()) { + if ($this->session->isAjaxRequest()) { throw new AjaxRestrictedException('This application does not allow ajax requests.'); } } From f9fcb3e3b91868e515aa3860284ddea00c9669a0 Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 14:36:39 -0700 Subject: [PATCH 15/25] Update SessionMiddleware.php --- src/SessionMiddleware.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index c6eee07..27bd5a8 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -55,12 +55,12 @@ public function handle(callable $next) if ($this->session->fingerprintEnabled()) { $fingerprint = $this->session->generateUniqueFingerprint(); if ($this->session->has('cytrenna.fingerprint')) { - if (!hash_equals($this->has('cytrenna.fingerprint'), $fingerprint)) { - $this->stopSession(); + if (!hash_equals($this->session->has('cytrenna.fingerprint'), $fingerprint)) { + $this->session->stopSession(); throw new InvalidFingerprintException('The fingerprint supplied is invalid.'); } } else { - $this->put('cytrenna.fingerprint', $fingerprint); + $this->session->put('cytrenna.fingerprint', $fingerprint); } } // Prevent AJAX requests. From e28a41fa2fca45f4cc1f90960146cc17d1aaa5fc Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 14:50:35 -0700 Subject: [PATCH 16/25] Update SessionManager.php --- src/SessionManager.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/SessionManager.php b/src/SessionManager.php index 011514f..ea4b7f7 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -96,15 +96,15 @@ public function start(): bool */ public function stop(): bool { - $_SESSION = array(); - if (ini_get("session.use_cookies")) { - $params = session_get_cookie_params(); - setcookie(session_name(), '', time() - 42000, - $params["path"], $params["domain"], - $params["secure"], $params["httponly"] - ); + // Attempt to destory the session if running. + try { + $this->isRunning(); + } catch (SessionRunningException $e) { + $this->clear(); + $this->voidSessionCookie(); } - return session_destroy(); + $this->freeSessionID(); + $this->destroySession(); } /** From 81ebf15789b8f4b4b9813688558bf27ec2367419 Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 14:59:16 -0700 Subject: [PATCH 17/25] Update SessionManager.php --- src/SessionManager.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/SessionManager.php b/src/SessionManager.php index ea4b7f7..83d0bb2 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -94,17 +94,23 @@ public function start(): bool /** * {@inheritdoc} */ - public function stop(): bool + public function stopSession(): bool { // Attempt to destory the session if running. try { $this->isRunning(); } catch (SessionRunningException $e) { + // Clear all session variables $this->clear(); + // Void the session cookie $this->voidSessionCookie(); + // Free the session ID. + $this->freeSessionID(); + // Destroy the session. + return $this->destroySession(); + } catch (SessionClosedException $e) { + return true; } - $this->freeSessionID(); - $this->destroySession(); } /** From 8392a6eef3d3176910f5233dadd5758d067be9e2 Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 15:13:32 -0700 Subject: [PATCH 18/25] Update SessionManager.php --- src/SessionManager.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/SessionManager.php b/src/SessionManager.php index 83d0bb2..006a439 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -116,12 +116,14 @@ public function stopSession(): bool /** * {@inheritdoc} */ - public function exists(): bool + public function isRunning(): void { if (php_sapi_name() !== 'cli') { - return session_status() === PHP_SESSION_ACTIVE ? true : false; + if (session_status() === PHP_SESSION_ACTIVE) { + throw SessionRunningException('The session is running.'); + } } - return false; + throw SessionClosedException('The session is closed.); } /** From dce6bcced3dfb7b337c92f8c305afbf1ff59a75e Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 15:30:58 -0700 Subject: [PATCH 19/25] Update SessionManager.php --- src/SessionManager.php | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/SessionManager.php b/src/SessionManager.php index 006a439..58d553b 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -94,42 +94,39 @@ public function start(): bool /** * {@inheritdoc} */ - public function stopSession(): bool + public function stopSession(bool $logout = false): bool { // Attempt to destory the session if running. - try { - $this->isRunning(); - } catch (SessionRunningException $e) { + if ($this->isRunning()) { // Clear all session variables $this->clear(); // Void the session cookie $this->voidSessionCookie(); // Free the session ID. $this->freeSessionID(); + // Regenerate session ID. + if ($logout) + $this->regenerateSessionID(); // Destroy the session. return $this->destroySession(); - } catch (SessionClosedException $e) { - return true; } + return true; } /** * {@inheritdoc} */ - public function isRunning(): void + public function isRunning(): bool { - if (php_sapi_name() !== 'cli') { - if (session_status() === PHP_SESSION_ACTIVE) { - throw SessionRunningException('The session is running.'); - } - } - throw SessionClosedException('The session is closed.); + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') + return false; + return session_status() === PHP_SESSION_ACTIVE; } /** * {@inheritdoc} */ - public function regenerate(bool $deleteOldSession = true): bool + public function regenerateSessionID(bool $deleteOldSession = true): bool { return session_regenerate_id($deleteOldSession); } From eef38de2a0d7f71c2d724688fd5b67dbb569637c Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 15:32:47 -0700 Subject: [PATCH 20/25] Update SessionManager.php --- src/SessionManager.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SessionManager.php b/src/SessionManager.php index 58d553b..41bd957 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -118,8 +118,10 @@ public function stopSession(bool $logout = false): bool */ public function isRunning(): bool { + // Return false on the command line cli. if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') return false; + // Return the current session status. return session_status() === PHP_SESSION_ACTIVE; } @@ -128,6 +130,7 @@ public function isRunning(): bool */ public function regenerateSessionID(bool $deleteOldSession = true): bool { + // Regenerate the session ID. return session_regenerate_id($deleteOldSession); } From ee71b6ffc8c6bd579a7e9c3f479cd1fc600048fa Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 15:41:02 -0700 Subject: [PATCH 21/25] Update SessionManager.php --- src/SessionManager.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/SessionManager.php b/src/SessionManager.php index 41bd957..2d3491a 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -134,6 +134,43 @@ public function regenerateSessionID(bool $deleteOldSession = true): bool return session_regenerate_id($deleteOldSession); } + /** + * {@inheritdoc} + */ + public function clear(): bool + { + // Clear all session variable. + $_SESSION = array(); + } + + /** + * {@inheritdoc} + */ + public function voidSessionCookie(): bool + { + // Void the session cookie. + if (ini_get("session.use_cookies") && isset($_COOKIE[session_name()])) { + // Get the cookie params. + $params = session_get_cookie_params(); + // Delete the cookie. + setcookie(session_name(), '', time() - 42000, + $params["path"] ?? '/', + $params["domain"] ?? '', + $params["secure"] ?? false, + $params["httponly"] ?? false + ); + } + } + + /** + * {@inheritdoc} + */ + public function freeSessionID(): bool + { + // Free the session ID. + session_unset(); + } + /** * {@inheritdoc} */ From a14acb25b03e7e44d6484149b7d84c493ddffd27 Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 15:48:27 -0700 Subject: [PATCH 22/25] Update SessionManager.php --- src/SessionManager.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/SessionManager.php b/src/SessionManager.php index 2d3491a..c763685 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -176,6 +176,7 @@ public function freeSessionID(): bool */ public function has(string $key): bool { + // Check to see if the session variable is set. return isset($_SESSION[$key]); } @@ -192,8 +193,11 @@ public function get(string $key, $defaultValue = null) */ public function flash(string $key, $defaultValue = null) { + // Retrieve the session variable. $value = $this->get($key, $defaultValue); + // Unset the session variable. $this->delete($key); + // Return the value. return $value; } @@ -202,7 +206,11 @@ public function flash(string $key, $defaultValue = null) */ public function put(string $key, $value): void { - $_SESSION[$key] = $value; + // Check to see if the session is running. + if ($this->isRunning()) { + // Set a seasion variable. + $_SESSION[$key] = $value; + } } /** From adaaa1587b122a1ef5aace745497eb60abb0560e Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Wed, 6 Aug 2025 15:50:25 -0700 Subject: [PATCH 23/25] Update SessionManager.php --- src/SessionManager.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SessionManager.php b/src/SessionManager.php index c763685..251c1a8 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -218,7 +218,11 @@ public function put(string $key, $value): void */ public function delete(string $key): void { - unset($_SESSION[$key]); + // Check to see if the session is running. + if ($this->isRunning()) { + // Unset the session variable. + unset($_SESSION[$key]); + } } /** From 9c648ea08c016a6a44b0ff9a1c5224dc4d485188 Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Mon, 11 Aug 2025 22:40:37 -0700 Subject: [PATCH 24/25] Update SessionManager.php --- src/SessionManager.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/SessionManager.php b/src/SessionManager.php index 251c1a8..3acf4b5 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -176,8 +176,11 @@ public function freeSessionID(): bool */ public function has(string $key): bool { - // Check to see if the session variable is set. - return isset($_SESSION[$key]); + if ($this->isRunning()) { + // Check to see if the session variable is set. + return isset($_SESSION[$key]); + } + return false; } /** @@ -185,7 +188,10 @@ public function has(string $key): bool */ public function get(string $key, $defaultValue = null) { - return $this->has($key) ? $_SESSION[$key] : $defaultValue; + // Check to see if the session is running. + if ($this->isRunning()) { + return $this->has($key) ? $_SESSION[$key] : $defaultValue; + } } /** @@ -193,12 +199,16 @@ public function get(string $key, $defaultValue = null) */ public function flash(string $key, $defaultValue = null) { - // Retrieve the session variable. - $value = $this->get($key, $defaultValue); - // Unset the session variable. - $this->delete($key); - // Return the value. - return $value; + // Check to see if the session is running. + if ($this->isRunning()) { + // Retrieve the session variable. + $value = $this->get($key, $defaultValue); + // Unset the session variable. + $this->delete($key); + // Return the value. + return $value; + } + return $defaultValue; } /** From 1a7ae78d22ddd65455dec26b18f692f6e87857ce Mon Sep 17 00:00:00 2001 From: Nicholas <47761650+omatamix@users.noreply.github.com> Date: Tue, 12 Aug 2025 12:17:25 -0700 Subject: [PATCH 25/25] Update SessionMiddleware.php --- src/SessionMiddleware.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index 27bd5a8..3bd9044 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -2,7 +2,7 @@ /** * MIT License * - * Copyright (c) 2021 Nicholas English + * Copyright (c) 2026 Nicholas English * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -48,9 +48,7 @@ public function __construct(SessionManager $session) public function handle(callable $next) { // Start the session if not already started. - try { - $this->session->isRunning(); - } catch (SessionClosedException $e) { + if ($this->session->isRunning()) { // Validate the session fingerprint. if ($this->session->fingerprintEnabled()) { $fingerprint = $this->session->generateUniqueFingerprint();