You are here

public function GeoIpHandlerV2::regionCode in GeoIP API 7.2

The region code for a given IP.

This will just return the most accurate subdivision if there are multiple levels.

Parameters

string $ip: The ip to resolve.

Return value

string|FALSE The region name or FALSE on failure. Code is always upper case.

Overrides GeoIpHandlerInterface::regionCode

File

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

Class

GeoIpHandlerV2

Namespace

Drupal\geoip

Code

public function regionCode($ip = NULL) {
  try {
    $subdivisions = $this
      ->record($ip)->subdivisions;
    if ($subdivision = end($subdivisions)) {
      return strtoupper($subdivision->isoCode);
    }
  } catch (\Exception $e) {
    return FALSE;
  }
}