<html>
<head>
    <title>Mike's GeoDump</title>
</head>
<style type="text/css">
body {
    font-family: arial;
    font-size: 12pt;
}
</style>
<body>
<a href="http://www.westwideweb.com/wp/2008/07/20/where-am-i-php-pear-net_geoip-and-me-geo-location-by-ip/">The Post That Started it All</a>
<br />
<hr />
<script language="php">
require_once 'Net/GeoIP.php';
$geoip Net_GeoIP::getInstance("GeoIP/GeoLiteCity.dat");
$ip=getMyIP();
print( 
"<h2>$ip</h2>\n" );
$us $geoip->lookupLocation($ip);
dumpLocation($us);

print( 
"<hr />\n" );

$ip getVisitorIP();
$them $geoip->lookupLocation($ip);
print( 
"<h2>$ip My Visitor (in other words, you)</h2>\n" );
dumpLocation($them);

print( 
"<hr />\n" );
$km $us->distance$them );   // This is the really helpful thing for my purposes.
$miles $km * (float)0.621371192// Grabbed the .621... from Google
printf"I reckon we're about %f km apart (%f miles).\n"$km$miles );

$geoip->close();

print (
"<br /><h3>How'd they do That? Source:</h3><hr />\n" );

highlight_file"geoTest.sample.php" );

function
getMyIP() {
    return 
$_SERVER['SERVER_ADDR'];
}

function
getVisitorIP() {
    return 
$_SERVER['REMOTE_ADDR'];
}

function
dumpLocation($location) {
</script>
    <table>
    <tr><td>ISO Country Code</td><td><?=$location->countryCode?></td></tr>
    <tr><td>Country Name</td><td><?=$location->countryName?></td></tr>
    <tr><td>Region</td><td><?=$location->region?></td></tr>
    <tr><td>City</td><td><?=$location->city?></td></tr>
    <tr><td>Postal Code</td><td><?=$location->postalCode?></td></tr>
    <tr><td>Latitude</td><td><?=$location->latitude?></td></tr>
    <tr><td>Longitude</td><td><?=$location->longitude?></td></tr>
    <tr><td>Area Code</td><td><?=$location->areaCode?></td></tr>
    <tr><td>DMA Code</td><td><?=$location->dmaCode?></td></tr>
    </table>
<script language="php">
}
</script>
</body>
</html>