You are here

function geoip_country_code in GeoIP API 7

Same name and namespace in other branches
  1. 5 geoip.module \geoip_country_code()
  2. 6 geoip.module \geoip_country_code()
  3. 7.2 geoip.module \geoip_country_code()

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.

Return value

string Country Code

Related topics

2 calls to geoip_country_code()
geoip_language_detect_language in geoip_language/geoip_language.module
Return the language object mapped to the current GeoIP detected country.
page_cache_fastpath in geoip_language/geoip_language.fastpath.inc
Some sort of caching.

File

./geoip.module, line 161
API for using the MaxMind GeoLite Country database.

Code

function geoip_country_code($ip = NULL) {
  $ip = $ip ? $ip : geoip_ip_address();
  $gi = geoip_instance();
  if (!$gi) {
    return FALSE;
  }
  $cc = geoip_country_code_by_addr($gi, $ip);
  geoip_close($gi);
  if (variable_get('geoip_debug', FALSE) && !empty($_GET['geoip_debug'])) {
    drupal_set_message(t('GeoIP reports country: %cc', array(
      '%cc' => $cc,
    )));
  }
  return $cc;
}