From 7c5ddecc66db88c28b75e35a38ea1861888adb6d Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Thu, 11 Oct 2012 14:52:47 -0400 Subject: [PATCH] Fixed incorrect array handling in cookie container. --- module/VuFind/src/VuFind/Cookie/Container.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/module/VuFind/src/VuFind/Cookie/Container.php b/module/VuFind/src/VuFind/Cookie/Container.php index ce2fc178dd5..ac274214da5 100644 --- a/module/VuFind/src/VuFind/Cookie/Container.php +++ b/module/VuFind/src/VuFind/Cookie/Container.php @@ -94,8 +94,12 @@ class Container { $_COOKIE[$this->groupName . $var] = $value; if (is_array($value)) { + $i = 0; foreach ($value as $curr) { - setcookie($this->groupName . $var . '[]', $curr, null, '/'); + setcookie( + $this->groupName . $var . '[' . $i . ']', $curr, null, '/' + ); + $i++; } } else { setcookie($this->groupName . $var, $value, null, '/'); @@ -125,7 +129,19 @@ class Container */ public function __unset($var) { + $isArray = is_array($_COOKIE[$this->groupName . $var]); + if ($isArray) { + $count = count($_COOKIE[$this->groupName . $var]); + } unset($_COOKIE[$this->groupName . $var]); - setcookie($this->groupName . $var, '', time() - 3600, '/'); + if ($isArray) { + for ($i = 0; $i < $count; $i++) { + setcookie( + $this->groupName . $var . '[' . $i . ']', '', time() - 3600, '/' + ); + } + } else { + setcookie($this->groupName . $var, '', time() - 3600, '/'); + } } } \ No newline at end of file -- GitLab