Skip to content

Commit d6f99c1

Browse files
feat(geolocation): Use session only if save_in_session setting is still active
1 parent 9c69188 commit d6f99c1

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Geolocation.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,16 @@ public function getCountryResult(array $geolocConfig, string $ip): array
7676
{
7777
$result = $this->resultTemplate;
7878
$saveInSession = !empty($geolocConfig['save_in_session']);
79-
if ($country = Session::getSessionVariable('crowdsec_geolocation_country')) {
80-
$result['country'] = $country;
79+
if($saveInSession){
80+
if ($country = Session::getSessionVariable('crowdsec_geolocation_country')) {
81+
$result['country'] = $country;
8182

82-
return $result;
83-
} elseif ($notFoundError = Session::getSessionVariable('crowdsec_geolocation_not_found')) {
84-
$result['not_found'] = $notFoundError;
83+
return $result;
84+
} elseif ($notFoundError = Session::getSessionVariable('crowdsec_geolocation_not_found')) {
85+
$result['not_found'] = $notFoundError;
8586

86-
return $result;
87+
return $result;
88+
}
8789
}
8890
if (Constants::GEOLOCATION_TYPE_MAXMIND === $geolocConfig['type']) {
8991
$configPath = $geolocConfig[Constants::GEOLOCATION_TYPE_MAXMIND];

0 commit comments

Comments
 (0)