Skip to content

Commit

Permalink
Fix based on lukeyouell#19
Browse files Browse the repository at this point in the history
  • Loading branch information
bzin committed Feb 21, 2020
1 parent db70751 commit 3bad109
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/services/GeoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ 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->cached = true;
$location = @unserialize($cookie->value);
if ($location === false) {
$location = $cookie->value;
}
//$location->cached = true;

return $location;
} else {
// Cookie doesn't exist, so fetch the user's location using api source and store it as a cookie, set 'cached' to false to show that the cookie didn't exist
$apiSource = $settings->apiSource;
$location = $this->getLocation($settings, $ipAddress);
$location = unserialize($this->getLocation($settings, $ipAddress));
// $location->cached = false;

// Log this
Expand Down Expand Up @@ -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)
]));
Expand Down

0 comments on commit 3bad109

Please sign in to comment.