Finding the location of an IP Address

The following is a quick and simple way to find the general location of an IP Address. This tool only locates the region the IP Address is located in, not the exact location of the visitor. This identifies the location of the ISP that hosts the visitor. However, this can be useful.

[evalphp]
function theLocation($user_ip) {
$meta_tags =
get_meta_tags(‘http://www.geobytes.com/IPLocator.htm?GetLocation&template=php3.txt&IPAddress=’ . $user_ip) or die(‘Error getting meta tags’);
$city = $meta_tags[‘city’];
$state = $meta_tags[‘regioncode’];
$country = $meta_tags[‘fips104’];
$lat = $meta_tags[‘latitude’];
$lng = $meta_tags[‘longitude’];
return array($city, $state, $country, $lat, $lng ) ;
}
$visitor = $_SERVER[“REMOTE_ADDR”];

list($city, $state, $country, $lat, $lng) = theLocation($visitor) ;

echo “

Your Info: ” . $visitor . ” ⇒ ” . $city . “, ” . $state . “, ” . $country , “

” ;
[/evalphp]



    function theLocation($user_ip) {
        $meta_tags = get_meta_tags(
             'http://www.geobytes.com/IPLocator.htm?
             GetLocation&template=php3.txt&IPAddress=' . 
             $user_ip) or 
             die('Error getting meta tags');
        $city = $meta_tags['city'];
        $state = $meta_tags['regioncode'];
        $country = $meta_tags['fips104'];
        $lat = $meta_tags['latitude'];
        $long = $meta_tags['longitude'];
        return array($city, $state, $country, $lat, $lng ) ;
    }

    $visitor = $_SERVER["REMOTE_ADDR"];
  
    list($city, $state, $country, $lat, $lng) = 
        theLocation($visitor) ;
    echo "<p>Your Info: " . $visitor . 
            " &rArr; " . $city . ", " . 
            $state . ", " . $country , "</p>" ;

Leave a Reply