From 74e95d35edf38b6d3244cf862186454a5df67fdb Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Thu, 19 Apr 2018 23:55:05 -0500 Subject: [PATCH] Session DatabaseHandler was not reading back values correctly. Fixes #958 --- system/Session/Handlers/DatabaseHandler.php | 6 ++++-- system/Session/Session.php | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/system/Session/Handlers/DatabaseHandler.php b/system/Session/Handlers/DatabaseHandler.php index ae67a81b31b0..e22553ff8d6a 100644 --- a/system/Session/Handlers/DatabaseHandler.php +++ b/system/Session/Handlers/DatabaseHandler.php @@ -35,9 +35,9 @@ * @since Version 3.0.0 * @filesource */ +use Config\Database; use CodeIgniter\Config\BaseConfig; use CodeIgniter\Database\BaseConnection; -use Config\Database; /** * Session handler using current Database for storage @@ -169,7 +169,9 @@ public function read($sessionID) $builder = $builder->where('ip_address', $_SERVER['REMOTE_ADDR']); } - if ($result = $builder->get()->getRow() === null) + $result = $builder->get()->getRow(); + + if ($result === null) { // PHP7 will reuse the same SessionHandler object after // ID regeneration, so we need to explicitly set this to diff --git a/system/Session/Session.php b/system/Session/Session.php index f1e86add74f8..99779f011a81 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -166,6 +166,8 @@ public function __construct(\SessionHandlerInterface $driver, $config) $this->cookieDomain = $config->cookieDomain; $this->cookiePath = $config->cookiePath; $this->cookieSecure = $config->cookieSecure; + + helper('array'); } //-------------------------------------------------------------------- @@ -463,9 +465,9 @@ public function set($data, $value = null) */ public function get(string $key = null) { - if (isset($key)) + if ($value = dot_array_search($key, $_SESSION)) { - return $_SESSION[$key] ?? null; + return $value; } elseif (empty($_SESSION)) {