Net_GeoIP::lookupLocation() – returns the location record for specified IP address


require_once "Net/GeoIP.php";

object lookupLocation() ( string $addr )


This method returns an instance of Net_GeoIP_Location for the specified IP address. It works only with a non-free City database.

Looking up the location record

require_once "Net/GeoIP.php";

$geoip Net_GeoIP::getInstance("/path/to/geoipdb.dat");

try {
$location $geoip->lookupLocation($_SERVER['REMOTE_ADDR']);


printf("City: %s, %s\nLatitude: %s, Longitude: %s\n",

} catch (
Exception $e) {
// Handle exception



This method throws an exception if the IP address is invalid.

returns the region for given IP address. (Previous) returns the name of the organization or ISP for the given IP address. (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

Note by:
Can someone post a example on how to use this filter with the FREE city database (GeoLiteCity.dat).

I got the Country lookup working and thought the city lookup is prcedurally identical, but I guess not.

here is the code that I have for city lookup. am I missing something??

require_once 'PEAR/Net/GeoIP.php';
require_once 'PEAR/Net/GeoIP/Location.php';

$geoipCountry = Net_GeoIP::getInstance('PEAR/Net/GeoIP/GeoIP.dat');
$geoipCity = Net_GeoIP::getInstance('PEAR/Net/GeoIP/GeoLiteCity.dat');

try {
echo '<br><br>';
echo $country_name;

//echo '<br><br>';
//echo $city_name;


printf("City: %s, %s\nLatitude: %s, Longitude: %s\n",
$location->city, $location->region,
$location->latitude, $location->longitude);


catch (Exception $e)
{ // Handle exception
Note by:
It works with the free City database GeoLiteCity.dat
available from