function eu_cookie_compliance_user_in_eu in EU Cookie Compliance (GDPR Compliance) 7.2
Same name and namespace in other branches
- 8 eu_cookie_compliance.module \eu_cookie_compliance_user_in_eu()
- 7 eu_cookie_compliance.module \eu_cookie_compliance_user_in_eu()
- 2.0.x eu_cookie_compliance.module \eu_cookie_compliance_user_in_eu()
Check if the user is in the EU.
2 calls to eu_cookie_compliance_user_in_eu()
- eu_cookie_compliance_json in ./
eu_cookie_compliance.module - Menu callback for return JSON EU visitor status.
- eu_cookie_compliance_page_build in ./
eu_cookie_compliance.module - Implements hook_page_build().
File
- ./
eu_cookie_compliance.module, line 674 - EU cookie compliance primary module file.
Code
function eu_cookie_compliance_user_in_eu() {
$geoip_match = FALSE;
$eu_countries_default = array(
NULL,
'AT',
'AX',
'BE',
'BG',
'CY',
'CZ',
'DE',
'DK',
'EE',
'EL',
'ES',
'EU',
'FI',
'FR',
'GB',
'GF',
'GI',
'GP',
'GR',
'HR',
'HU',
'IE',
'IS',
'IT',
'LI',
'LT',
'LU',
'LV',
'ME',
'MF',
'MQ',
'MT',
'NL',
'NO',
'PL',
'PT',
'RE',
'RO',
'SE',
'SI',
'SK',
'YT',
'UK',
);
// Allow custom array of countries to be loaded from settings.php, defaulting
// to the array above.
$eu_countries = variable_get('eu_cookie_compliance_eu_countries', $eu_countries_default);
$country_code = extension_loaded('geoip') ? geoip_country_code_by_name(ip_address()) : '';
if (module_exists('geoip')) {
$country_code = geoip_country_code();
}
elseif (module_exists('smart_ip')) {
$smart_ip_session = smart_ip_session_get('smart_ip');
$country_code = isset($smart_ip_session['location']['country_code']) ? $smart_ip_session['location']['country_code'] : NULL;
}
// If the CloudFlare provided country header is available, use it as a
// fallback. See:
// https://support.cloudflare.com/hc/en-us/articles/200168236-What-does-Cloudflare-IP-Geolocation-do-
if (empty($country_code) && isset($_SERVER['HTTP_CF_IPCOUNTRY'])) {
$country_code = $_SERVER['HTTP_CF_IPCOUNTRY'];
}
if (in_array($country_code, $eu_countries)) {
$geoip_match = TRUE;
}
if ($country_code == '' || $country_code == '-') {
$geoip_match = TRUE;
}
return array(
'country' => $country_code,
'in_eu' => $geoip_match,
);
}