Skip to content

Instantly share code, notes, and snippets.

@alnorth
Created May 2, 2011 08:57
Show Gist options
  • Save alnorth/951319 to your computer and use it in GitHub Desktop.
Save alnorth/951319 to your computer and use it in GitHub Desktop.
<?php
function hostip_get_info($ip) {
$content = @file_get_contents('http://api.hostip.info/?ip='.$ip);
if ($content != FALSE) {
$xml = new SimpleXmlElement($content);
$coordinates = $xml->children('gml', TRUE)->featureMember->children('', TRUE)->Hostip->ipLocation->children('gml', TRUE)->pointProperty->Point->coordinates;
$longlat = explode(',', $coordinates);
$location['longitude'] = $longlat[0];
$location['latitude'] = $longlat[1];
$location['citystate'] = '==>'.$xml->children('gml', TRUE)->featureMember->children('', TRUE)->Hostip->children('gml', TRUE)->name;
$location['country'] = '==>'.$xml->children('gml', TRUE)->featureMember->children('', TRUE)->Hostip->countryName;
return $location;
}
else return false;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment