Getting location details from IP in PHP

Biranchi picture Biranchi · Dec 2, 2009 · Viewed 7k times · Source

Is it possible to get the location details from the users IP Address in PHP.

Any suggestions ??

Thanks

Answer

David Barnes picture David Barnes · Dec 2, 2009
$ip = '98.229.152.237';
$xml = simplexml_load_file("http://ipinfodb.com/ip_query.php?ip=$ip");
print_r($xml);

Output:

SimpleXMLElement Object
(
    [Ip] => 98.229.152.237
    [Status] => OK
    [CountryCode] => US
    [CountryName] => United States
    [RegionCode] => 33
    [RegionName] => New Hampshire
    [City] => Manchester
    [ZipPostalCode] => 03103
    [Latitude] => 42.9403
    [Longitude] => -71.4435
    [Timezone] => -5
    [Gmtoffset] => -5
    [Dstoffset] => -4
)