Rob van der Woude's Scripting Pages

Web WhoAmI

 

Your IP address is 54.204.104.71
Your location is United States (USA)

 

You are probably familiar with the WHOAMI command.
This is a web version of that command Smiley

 

PHP Code:
<?php
$ip     = $_SERVER['REMOTE_ADDR'];
$xmlstr = file_get_contents( "http://www.webservicex.net/geoipservice.asmx/GetGeoIP?IPAddress={$ip}" );
$xml    = new SimpleXMLElement( $xmlstr );
$rc     = $xml->ReturnCode[0];
if ( $rc == 1 ) {
    $countryname = ucwords( strtolower( $xml->CountryName[0] ) );
    $countrycode = $xml->CountryCode[0];
} else {
    $countryname = 'Unknown';
    $countrycode = '--';
}
print "<p>Your IP address is {$ip}<br>\n Your location is {$countryname} ({$countrycode})</p>";
?>

 

As you can see in the code, it is based on webservicex.net's GetGeoIP functionality.

Note: A note from Stan Littlefield: for local use, replace $ip = $_SERVER['REMOTE_ADDR']; by $ip = file_get_contents('http://whatismyip.org/');

page last uploaded: 2015-08-24, 21:18