You are here

function ip2country_get_country in IP-based Determination of a Visitor's Country 8

Same name and namespace in other branches
  1. 6 ip2country.module \ip2country_get_country()
  2. 7 ip2country.module \ip2country_get_country()

Gets the ISO 3166 2-character country code from the IP address.

Parameters

string|int $ip_address: IP address either as a dotted quad string (e.g. "127.0.0.1") or as a 32-bit unsigned long integer.

Return value

string|false ISO 3166-1 2-character country code for this IP address, or FALSE if the lookup failed to find a country.

Deprecated

in ip2country:8.x-1.9 and is removed from ip2country:8.x-2.0. Use the ip2country.lookup service instead. For example, \Drupal::service('ip2country.lookup')->getCountry($ip_address).

See also

https://www.drupal.org/node/3076484

File

./ip2country.module, line 151
Determination of user's Country based on IP.

Code

function ip2country_get_country($ip_address) {
  @trigger_error("ip2country_get_country() is deprecated in ip2country:8.x-1.9 and is removed from ip2country:8.x-2.0. Use \\Drupal::service('ip2country.lookup')->getCountry() instead. See https://www.drupal.org/node/3076484", E_USER_DEPRECATED);
  return \Drupal::service('ip2country.lookup')
    ->getCountry($ip_address);
}