Created
March 18, 2011 07:58
-
-
Save z0w0/875757 to your computer and use it in GitHub Desktop.
A snippet for finding the geolocation of an IP. @api.hostip.info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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