You are here

public function GeoIpHandlerV2::countryCode in GeoIP API 7.2

Returns the ISO 3166-2 country code for a given IP.

Defaults to using the current user's IP if not specified.

Parameters

string $ip: The ip to resolve.

Return value

string|FALSE Country code or FALSE on failure. Code is always upper case.

Overrides GeoIpHandlerInterface::countryCode

File

src/GeoIpHandlerV2.php, line 126
The GeoIP API handler for version 2.

Class

GeoIpHandlerV2

Namespace

Drupal\geoip

Code

public function countryCode($ip = NULL) {
  try {
    return strtoupper($this
      ->record($ip)->country->isoCode);
  } catch (\Exception $e) {
    return FALSE;
  }
}