You are here

function geoip_country_code_by_addr in GeoIP API 7

Same name and namespace in other branches
  1. 6 lib/geoip.inc \geoip_country_code_by_addr()
1 call to geoip_country_code_by_addr()
geoip_country_code in ./geoip.module
API function to return the country code for a given IP. Defaults to using the current user's IP if not specified. This function works with both the country and city level databases.

File

lib/geoip.inc, line 391

Code

function geoip_country_code_by_addr($gi, $addr) {
  if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
    $record = geoip_record_by_addr($gi, $addr);
    if ($record !== false) {
      return $record->country_code;
    }
  }
  else {
    $country_id = geoip_country_id_by_addr($gi, $addr);
    if ($country_id !== false) {
      return $gi->GEOIP_COUNTRY_CODES[$country_id];
    }
  }
  return false;
}