You are here

function geoip_city in GeoIP API 6

Same name and namespace in other branches
  1. 7 geoip.module \geoip_city()

API function to return the city data for a given IP.

Defaults to using the current user's IP if not specified. This function only works with the city level database and will return FALSE in all other cases.

Parameters

Optional, string specifying an IP address.:

Return value

FALSE on errors.

Related topics

File

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

Code

function geoip_city($ip = NULL) {
  $ip = $ip ? $ip : geoip_ip_address();
  $gi = geoip_instance();
  if (!$gi) {
    return FALSE;
  }
  elseif ($gi->databaseType != GEOIP_CITY_EDITION_REV1) {

    // If not using a city database, there is nothing to do.
    geoip_close($gi);
    return FALSE;
  }
  $record = geoip_record_by_addr($gi, $ip);
  geoip_close($gi);
  if (variable_get('geoip_debug', FALSE) && !empty($_GET['geoip_debug'])) {
    drupal_set_message(t('GeoIP reports city: %city', array(
      '%city' => $record->city,
    )));
  }
  return $record;
}