From dd85ad6622f271c9f4a2e0fea3b0d6525b3061a5 Mon Sep 17 00:00:00 2001 From: Matthias Leuffen Date: Thu, 13 Jun 2024 10:18:46 +0200 Subject: [PATCH] sync --- src/SessionMiddleware.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index d5d0e5b..828a3a7 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -22,8 +22,9 @@ public function __construct( private int $ttl = 3600, private int $expires = 86400, private string $cookieName = "X-SESS", - private string $cookiePath = "/" + private ?string $cookiePath = null ) { + } @@ -64,6 +65,15 @@ public function _createSession(string $sessionId, &$sessionDataRef): Session public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { + + if ($this->cookiePath === null) { + if ($this->app->has("router")) { + $this->cookiePath = $this->app->router->getRoutePrefix(); + } else { + $this->cookiePath = "/"; + } + } + $newSessionId = null; $loadedSessionId = null;