From 982b12a239ce7d3b6710ae4c371a5d596cefc8dc Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 19 Mar 2019 13:47:35 +0200 Subject: [PATCH] Fixed session_start(): Setting option 'session.name' failed [#2408] --- CHANGELOG.md | 1 + system/src/Grav/Framework/Session/Session.php | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 223bc8931..90833c005 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ * Grav 1.6: Fixed settion caching in `FlexIndex` * Fixed some potential issues/bugs found by phpstan * Fixed regression in GPM packages casted to Array (ref, getgrav/grav-plugin-admin@e3fc4ce) + * Fixed session_start(): Setting option 'session.name' failed [#2408](https://github.com/getgrav/grav/issues/2408) # v1.6.0-rc.3 ## 02/18/2019 diff --git a/system/src/Grav/Framework/Session/Session.php b/system/src/Grav/Framework/Session/Session.php index 20d68fb0d..fb676d433 100644 --- a/system/src/Grav/Framework/Session/Session.php +++ b/system/src/Grav/Framework/Session/Session.php @@ -61,13 +61,13 @@ class Session implements SessionInterface } // Set default options. - $options += array( + $options += [ 'cache_limiter' => 'nocache', 'use_trans_sid' => 0, 'use_cookies' => 1, 'lazy_write' => 1, 'use_strict_mode' => 1 - ); + ]; $this->setOptions($options); @@ -160,11 +160,11 @@ class Session implements SessionInterface foreach ($value as $key2 => $value2) { $ckey = "{$key}.{$key2}"; if (isset($value2, $allowedOptions[$ckey])) { - $this->ini_set("session.{$ckey}", $value2); + $this->setOption($ckey, $value2); } } } elseif (isset($value, $allowedOptions[$key])) { - $this->ini_set("session.{$key}", $value); + $this->setOption($key, $value); } } } @@ -195,7 +195,9 @@ class Session implements SessionInterface $error = $last ? $last['message'] : 'Unknown error'; throw new SessionException('Failed to start session: ' . $error, 500); - } elseif ($user && !$user->isValid()) { + } + + if ($user && !$user->isValid()) { $this->clear(); throw new SessionException('User Invalid', 500); } @@ -337,7 +339,7 @@ class Session implements SessionInterface * @param string $key * @param mixed $value */ - protected function ini_set($key, $value) + protected function setOption($key, $value) { if (!\is_string($value)) { if (\is_bool($value)) { @@ -348,6 +350,6 @@ class Session implements SessionInterface } $this->options[$key] = $value; - ini_set($key, $value); + ini_set("session.{$key}", $value); } }