diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-09-30 09:37:32 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-09-30 09:37:32 +0400 |
commit | a00487b0b841c4b15463b591c7f62176c4b84d15 (patch) | |
tree | 6eb893ce356a4740e044c9cdadaf84ffb2095b9d /core/Cookie.php | |
parent | 0edef3332289a7cbe54b58084b967907d1086d29 (diff) |
coding style fixes, some PHPStorm inspection fixes, improved readability of code, few refactorings, all as part of our code cleanup strategy
Diffstat (limited to 'core/Cookie.php')
-rw-r--r-- | core/Cookie.php | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/core/Cookie.php b/core/Cookie.php index d081ec944e..7440c5795c 100644 --- a/core/Cookie.php +++ b/core/Cookie.php @@ -200,12 +200,14 @@ class Cookie private function extractSignedContent($content) { $signature = substr($content, -40); + if (substr($content, -43, 3) == self::VALUE_SEPARATOR . '_=' && $signature == sha1(substr($content, 0, -40) . SettingsPiwik::getSalt()) ) { // strip trailing: VALUE_SEPARATOR '_=' signature" return substr($content, 0, -43); } + return false; } @@ -218,6 +220,7 @@ class Cookie protected function loadContentFromCookie() { $cookieStr = $this->extractSignedContent($_COOKIE[$this->name]); + if ($cookieStr === false) { return; } @@ -255,6 +258,7 @@ class Cookie protected function generateContentString() { $cookieStr = ''; + foreach ($this->value as $name => $value) { if (!is_numeric($value)) { $value = base64_encode(safe_serialize($value)); @@ -335,6 +339,7 @@ class Cookie $this->value[$name] = $value; return; } + $this->value[$this->keyStore][$name] = $value; } @@ -347,14 +352,19 @@ class Cookie public function get($name) { $name = self::escapeValue($name); - if ($this->keyStore === false) { - return isset($this->value[$name]) - ? self::escapeValue($this->value[$name]) - : false; + if (false === $this->keyStore) { + if (isset($this->value[$name])) { + self::escapeValue($this->value[$name]); + } + + return false; + } + + if (isset($this->value[$this->keyStore][$name])) { + return self::escapeValue($this->value[$this->keyStore][$name]); } - return isset($this->value[$this->keyStore][$name]) - ? self::escapeValue($this->value[$this->keyStore][$name]) - : false; + + return false; } /** @@ -364,8 +374,9 @@ class Cookie */ public function __toString() { - $str = 'COOKIE ' . $this->name . ', rows count: ' . count($this->value) . ', cookie size = ' . strlen($this->generateContentString()) . " bytes\n"; + $str = 'COOKIE ' . $this->name . ', rows count: ' . count($this->value) . ', cookie size = ' . strlen($this->generateContentString()) . " bytes\n"; $str .= var_export($this->value, $return = true); + return $str; } |