You are here

function _get_region in Smart IP 7.2

Same name and namespace in other branches
  1. 6.2 includes/geoip.inc \_get_region()
1 call to _get_region()
geoip_region_by_addr in includes/geoip.inc

File

includes/geoip.inc, line 736

Code

function _get_region($gi, $ipnum) {
  if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) {
    $seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV0;
    if ($seek_region >= 1000) {
      $country_code = "US";
      $region = chr(($seek_region - 1000) / 26 + 65) . chr(($seek_region - 1000) % 26 + 65);
    }
    else {
      $country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region];
      $region = "";
    }
    return array(
      $country_code,
      $region,
    );
  }
  else {
    if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
      $seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV1;

      //print $seek_region;
      if ($seek_region < US_OFFSET) {
        $country_code = "";
        $region = "";
      }
      else {
        if ($seek_region < CANADA_OFFSET) {
          $country_code = "US";
          $region = chr(($seek_region - US_OFFSET) / 26 + 65) . chr(($seek_region - US_OFFSET) % 26 + 65);
        }
        else {
          if ($seek_region < WORLD_OFFSET) {
            $country_code = "CA";
            $region = chr(($seek_region - CANADA_OFFSET) / 26 + 65) . chr(($seek_region - CANADA_OFFSET) % 26 + 65);
          }
          else {
            $country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET) / FIPS_RANGE];
            $region = "";
          }
        }
      }
      return array(
        $country_code,
        $region,
      );
    }
  }
}