function ip2country_user_country in IP-based Determination of a Visitor's Country 7
Determines if the user's country is one of the selected countries.
Parameters
array $countries: An array of ISO 3166-2 country codes to search.
Return value
bool TRUE if the user's country is found in $countries, FALSE otherwise.
1 string reference to 'ip2country_user_country'
- ip2country_rules_condition_info in ./
ip2country.rules.inc - Implements hook_rules_condition_info().
File
- ./
ip2country.rules.inc, line 54 - Rules integration for the ip2country module.
Code
function ip2country_user_country(array $countries = array()) {
global $user;
if (isset($user->data['country_iso_code_2'])) {
// Use the country stored in the $user object.
$country_code = $user->data['country_iso_code_2'];
}
else {
// Determine the user's country based on IP address of the page request.
$ip = ip_address();
$country_code = ip2country_get_country($ip);
}
return in_array($country_code, $countries);
}