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) ]));