private static function SmartIp::userLocationFallback in Smart IP 8.3
Same name and namespace in other branches
- 8.4 src/SmartIp.php \Drupal\smart_ip\SmartIp::userLocationFallback()
- 8.2 src/SmartIp.php \Drupal\smart_ip\SmartIp::userLocationFallback()
Use server's mod_geoip, X-GeoIP and Cloudflare IP Geolocation as fallback if the user's geolocation is empty.
Parameters
array $location: Location details.
1 call to SmartIp::userLocationFallback()
- SmartIp::updateUserLocation in src/
SmartIp.php - Update user's location only if the IP address stored in session is not the same as the IP address detected by the server or debug mode IP.
File
- src/
SmartIp.php, line 276 - Contains \Drupal\smart_ip\SmartIp.
Class
- SmartIp
- Smart IP static basic methods wrapper.
Namespace
Drupal\smart_ipCode
private static function userLocationFallback(array &$location) {
if (!isset($location['country']) && !isset($location['countryCode']) && !isset($location['region']) && !isset($location['regionCode']) && !isset($location['city']) && !isset($location['zip']) && !isset($location['latitude']) && !isset($location['longitude'])) {
if (function_exists('apache_note')) {
if ($country = apache_note('GEOIP_COUNTRY_NAME')) {
$location['country'] = $country;
}
if ($country_code = apache_note('GEOIP_COUNTRY_CODE')) {
$location['countryCode'] = $country_code;
}
if ($region = apache_note('GEOIP_REGION_NAME')) {
$location['region'] = $region;
}
if ($region_code = apache_note('GEOIP_REGION')) {
$location['regionCode'] = $region_code;
}
if ($city = apache_note('GEOIP_CITY')) {
$location['city'] = $city;
}
if ($zip = apache_note('GEOIP_POSTAL_CODE')) {
$location['zip'] = $zip;
}
if ($latitude = apache_note('GEOIP_LATITUDE')) {
$location['latitude'] = $latitude;
}
if ($longitude = apache_note('GEOIP_LONGITUDE')) {
$location['longitude'] = $longitude;
}
}
elseif (isset($_SERVER['HTTP_X_AKAMAI_EDGESCAPE'])) {
parse_str(str_replace(',', '&', $_SERVER['HTTP_X_AKAMAI_EDGESCAPE']), $esHeader);
if (isset($esHeader['country_code'])) {
module_load_include('inc', 'smart_ip', 'includes/smart_ip.country_list');
$countries = country_get_predefined_list();
$location['countryCode'] = $esHeader['country_code'];
$location['country'] = $countries[$esHeader['country_code']];
}
if (isset($esHeader['region'])) {
$location['region'] = $esHeader['region'];
}
if (isset($esHeader['region_code'])) {
$location['regionCode'] = $esHeader['region_code'];
$region = '';
if (isset($esHeader['region_code']) && isset($esHeader['country_code'])) {
$regionResult = smart_ip_get_region_static($esHeader['country_code'], $esHeader['region_code']);
$region = $regionResult[$esHeader['country_code']][$esHeader['region_code']];
}
$result['region'] = $region;
}
if (isset($esHeader['city'])) {
$location['city'] = $esHeader['city'];
}
if (isset($esHeader['zip'])) {
$location['zip'] = $esHeader['zip'];
}
if (isset($esHeader['lat'])) {
$location['latitude'] = $esHeader['lat'];
}
if (isset($esHeader['long'])) {
$location['longitude'] = $esHeader['long'];
}
}
else {
if (isset($_SERVER['GEOIP_COUNTRY_NAME'])) {
$location['country'] = $_SERVER['GEOIP_COUNTRY_NAME'];
}
elseif (isset($_SERVER['HTTP_X_GEOIP_COUNTRY'])) {
module_load_include('inc', 'smart_ip', 'includes/smart_ip.country_list');
$countries = country_get_predefined_list();
$location['country'] = $countries[$_SERVER['HTTP_X_GEOIP_COUNTRY']];
}
elseif (isset($_SERVER['HTTP_CF_IPCOUNTRY'])) {
module_load_include('inc', 'smart_ip', 'includes/smart_ip.country_list');
$countries = country_get_predefined_list();
$location['country'] = $countries[$_SERVER['HTTP_CF_IPCOUNTRY']];
}
if (isset($_SERVER['GEOIP_COUNTRY_CODE'])) {
$location['country'] = $_SERVER['GEOIP_COUNTRY_CODE'];
}
elseif (isset($_SERVER['HTTP_X_GEOIP_COUNTRY'])) {
$location['countryCode'] = $_SERVER['HTTP_X_GEOIP_COUNTRY'];
}
elseif (isset($_SERVER['HTTP_CF_IPCOUNTRY'])) {
$location['countryCode'] = $_SERVER['HTTP_CF_IPCOUNTRY'];
}
if (isset($_SERVER['GEOIP_REGION_NAME'])) {
$location['region'] = $_SERVER['GEOIP_REGION_NAME'];
}
if (isset($_SERVER['GEOIP_REGION'])) {
$location['regionCode'] = $_SERVER['GEOIP_REGION'];
}
if (isset($_SERVER['GEOIP_CITY'])) {
$location['city'] = $_SERVER['GEOIP_CITY'];
}
if (isset($_SERVER['GEOIP_POSTAL_CODE'])) {
$location['zip'] = $_SERVER['GEOIP_POSTAL_CODE'];
}
if (isset($_SERVER['GEOIP_LATITUDE'])) {
$location['latitude'] = $_SERVER['GEOIP_LATITUDE'];
}
if (isset($_SERVER['GEOIP_LONGITUDE'])) {
$location['longitude'] = $_SERVER['GEOIP_LONGITUDE'];
}
}
}
}