Created
March 26, 2010 18:16
-
-
Save bnvk/345202 to your computer and use it in GitHub Desktop.
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
if (!function_exists('get_geolocation')) { | |
function get_geolocation($ip) { | |
$d = file_get_contents("http://www.ipinfodb.com/ip_query.php?ip=$ip&output=xml"); | |
//Use backup server if cannot make a connection | |
if (!$d) { | |
$backup = file_get_contents("http://backup.ipinfodb.com/ip_query.php?ip=$ip&output=xml"); | |
$result = new SimpleXMLElement($backup); | |
if (!$backup) | |
return false; // Failed to open connection | |
} else { | |
$result = new SimpleXMLElement($d); | |
} | |
//Return the data as an array | |
return array('ip'=>$ip, 'country_code'=>$result->CountryCode, 'country_name'=>$result->CountryName, 'region_name'=>$result->RegionName, 'city'=>$result->City, 'zip_postal_code'=>$result->ZipPostalCode, 'latitude'=>$result->Latitude, 'longitude'=>$result->Longitude, 'timezone'=>$result->Timezone, 'gmtoffset'=>$result->Gmtoffset, 'dstoffset'=>$result->Dstoffset); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment