Take the 2-minute tour ×

I have access to the GeoIP.dat file through my current host but every IP I enter is empty. Any idea what might be wrong or a way to troubleshoot it? I have php errors on but I don't see anything wrong.

Here is my current script:



$gi = geoip_open("GeoIP.dat", GEOIP_STANDARD);

$rsGeoData = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);




The result always looks like this:

geoiprecord Object
[country_code] => 
[country_code3] => 
[country_name] => 
[region] => 
[city] => 
[postal_code] => 
[latitude] => -180
[longitude] => -180
[area_code] => 
[dma_code] => 
[metro_code] => 
[continent_code] => --
share|improve this question
depending on how your webserver is set up, $_SERVER['REMOTE_ADDR'] may not contain the client's ip address. Try echoing $_SERVER['REMOTE_ADDR'] to ensure the correct IP is there. –  thatjuan Dec 12 '11 at 21:01
I thought of that and have verified it's the correct IP. –  Paul Dec 12 '11 at 21:04
What does var_dump($_SERVER['REMOTE_ADDR']); output? Where is geoip_open and geoip_record_by_addr defined? What does GeoIP.dat specifically contains, both which format by what standard and what is the actual data? –  hakre Dec 12 '11 at 21:04
@Paul, try var_dump( is_readable("GeoIP.dat") ); to make sure you have read access to the dat file and to make sure that's the right path to it. –  thatjuan Dec 12 '11 at 21:05
juand: Looks like it's readable: boolean true (I had initially verified I could read the file) This is driving me crazy...everything seems to be correct –  Paul Dec 12 '11 at 21:06

1 Answer 1

up vote 2 down vote accepted

Make sure you are using the correct version of GeoIP. I have this code and it is working properly. Notice the different database file:


$gi = geoip_open('geolitecity.dat', GEOIP_STANDARD);
$record = geoip_record_by_addr($gi, ($_SERVER['REMOTE_ADDR'] == '') ? '' : $_SERVER['REMOTE_ADDR']);
share|improve this answer
Apparently I had an older version. That worked, thanks! –  Paul Dec 13 '11 at 0:37

Your Answer


