You are here

function visitors_get_geoip_data in Visitors 8

Same name and namespace in other branches
  1. 7.2 visitors.exit.inc \visitors_get_geoip_data()
  2. 7 visitors.exit.inc \visitors_get_geoip_data()

Retrieve geoip data for ip.

Parameters

ip: A string containing an ip address.

Return value

array geoip data array.

1 call to visitors_get_geoip_data()
visitors_exit in ./visitors.exit.inc
Implements of hook_exit().

File

./visitors.exit.inc, line 125
Implements of hook_exit().

Code

function visitors_get_geoip_data($ip) {
  $result = array(
    'continent_code' => '',
    'country_code' => '',
    'country_code3' => '',
    'country_name' => '',
    'region' => '',
    'city' => '',
    'postal_code' => '',
    'latitude' => '0',
    'longitude' => '0',
    'dma_code' => '0',
    'area_code' => '0',
  );
  if (function_exists('geoip_record_by_name')) {
    $data = @geoip_record_by_name($ip);
    if (!is_null($data) && $data !== FALSE) {

      /* Transform city value from iso-8859-1 into the utf8. */
      $data['city'] = utf8_encode($data['city']);
      $result = $data;
    }
  }
  return $result;
}