private static function SmartIp::userLocationFallback in Smart IP 8.2
Same name and namespace in other branches
- 8.4 src/SmartIp.php \Drupal\smart_ip\SmartIp::userLocationFallback()
- 8.3 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:
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.
File
- src/
SmartIp.php, line 131 - 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;
}
}
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'];
}
}
}
}