diff options
author | Aleksander Machniak <alec@alec.pl> | 2012-05-24 12:39:02 +0200 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2012-05-25 13:48:24 +0200 |
commit | f38035da17957f7bab514381044013a54ea19d8c (patch) | |
tree | 7e0a4fc683f8d2857266d4275ac0f6c5a811f927 /program/include/rcube_session.php | |
parent | 2712e3200c69aa2ebcfe488d7941c3ad77c917bb (diff) |
Remove possible confusion on session reads - PHP expects string result not boolean
Diffstat (limited to 'program/include/rcube_session.php')
-rw-r--r-- | program/include/rcube_session.php | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/program/include/rcube_session.php b/program/include/rcube_session.php index 53042b3bf..4ac395472 100644 --- a/program/include/rcube_session.php +++ b/program/include/rcube_session.php @@ -40,7 +40,7 @@ class rcube_session private $unsets = array(); private $gc_handlers = array(); private $cookiename = 'roundcube_sessauth'; - private $vars = false; + private $vars; private $key; private $now; private $secret = ''; @@ -137,11 +137,10 @@ class rcube_session $this->vars = base64_decode($sql_arr['vars']); $this->key = $key; - if (!empty($this->vars)) - return $this->vars; + return !empty($this->vars) ? (string) $this->vars : ''; } - return false; + return null; } @@ -160,7 +159,7 @@ class rcube_session // no session row in DB (db_read() returns false) if (!$this->key) { - $oldvars = false; + $oldvars = null; } // use internal data from read() for fast requests (up to 0.5 sec.) else if ($key == $this->key && (!$this->vars || $ts - $this->start < 0.5)) { @@ -170,7 +169,7 @@ class rcube_session $oldvars = $this->db_read($key); } - if ($oldvars !== false) { + if ($oldvars !== null) { $newvars = $this->_fixvars($vars, $oldvars); if ($newvars !== $oldvars) { @@ -200,7 +199,7 @@ class rcube_session */ private function _fixvars($vars, $oldvars) { - if ($oldvars !== false) { + if ($oldvars !== null) { $a_oldvars = $this->unserialize($oldvars); if (is_array($a_oldvars)) { foreach ((array)$this->unsets as $k) @@ -268,13 +267,13 @@ class rcube_session $this->vars = $arr['vars']; $this->key = $key; - if (!empty($this->vars)) - return $this->vars; + return !empty($this->vars) ? (string) $this->vars : ''; } - return false; + return null; } + /** * Save session data. * handler for session_read() @@ -289,21 +288,22 @@ class rcube_session // no session data in cache (mc_read() returns false) if (!$this->key) - $oldvars = false; + $oldvars = null; // use internal data for fast requests (up to 0.5 sec.) else if ($key == $this->key && (!$this->vars || $ts - $this->start < 0.5)) $oldvars = $this->vars; else // else read data again $oldvars = $this->mc_read($key); - $newvars = $oldvars !== false ? $this->_fixvars($vars, $oldvars) : $vars; - + $newvars = $oldvars !== null ? $this->_fixvars($vars, $oldvars) : $vars; + if ($newvars !== $oldvars || $ts - $this->changed > $this->lifetime / 2) return $this->memcache->set($key, serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $newvars)), MEMCACHE_COMPRESSED, $this->lifetime); - + return true; } + /** * Handler for session_destroy() with memcache backend * @@ -352,7 +352,7 @@ class rcube_session { session_regenerate_id($destroy); - $this->vars = false; + $this->vars = null; $this->key = session_id(); return true; @@ -375,13 +375,14 @@ class rcube_session return true; } - + + /** * Kill this session */ public function kill() { - $this->vars = false; + $this->vars = null; $this->ip = $_SERVER['REMOTE_ADDR']; // update IP (might have changed) $this->destroy(session_id()); rcmail::setcookie($this->cookiename, '-del-', time() - 60); |