From 8b39431de9f1d4dfcb82bf47d30157e7c6b32501 Mon Sep 17 00:00:00 2001 From: Anthony Cook Date: Thu, 27 Jul 2023 12:44:59 +1200 Subject: [PATCH] Fixes https://github.com/lukeyouell/craft-geocookie/issues/19 --- src/services/GeoService.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/services/GeoService.php b/src/services/GeoService.php index 758ae94..ae76b66 100644 --- a/src/services/GeoService.php +++ b/src/services/GeoService.php @@ -32,7 +32,10 @@ public function location() if ($cookie) { // Cookie already exists, so set the location as the cookie value and set 'cached' to true to show that the cookie already existed - $location = $cookie->value; + $location = @unserialize($cookie->value); + if ($location === false) { + $location = $cookie->value; + } $location->cached = true; return $location; @@ -175,7 +178,7 @@ public function getLocation($settings, $ipAddress) $cookies->add(new \yii\web\Cookie([ 'name' => $settings->cookieName, - 'value' => $location, + 'value' => serialize($location), // current timestamp + (cookieDuration setting in hours x number of seconds in an hour) 'expire' => time() + ($settings->cookieDuration * 3600) ]));