Skip to content

Instantly share code, notes, and snippets.

@z0w0
Created March 18, 2011 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z0w0/875757 to your computer and use it in GitHub Desktop.
Save z0w0/875757 to your computer and use it in GitHub Desktop.
A snippet for finding the geolocation of an IP. @api.hostip.info
function geolocate($ip)
{
$dom = new DOMDocument();
$dom->load("http://api.hostip.info/?ip=" . $ip);
$location = $dom->getElementsByTagName("countryName")->item(0)->nodeValue;
if($location == "" || $dom->getElementsByTagName("countryAbbrev")->item(0)->nodeValue == "XX")
$location = "N/A";
return $location;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment