Skip to content

Instantly share code, notes, and snippets.

@hboon
Created October 15, 2017 15:37
Show Gist options
  • Save hboon/48533e6d76fe5f37083a0c8127cb5954 to your computer and use it in GitHub Desktop.
Save hboon/48533e6d76fe5f37083a0c8127cb5954 to your computer and use it in GitHub Desktop.
Using IP Sidekick for geolocation in PHP
<?
//Using IP Sidekick for geolocation in PHP
//hboon@motionobj.com
//https://ipsidekick.com
//This uses the free plan which limits you to 1440 lookups/day.
//For a higher rate limit, look at our paid plans at https://ipsidekick.com
function resolveIP($ip) {
$string = file_get_contents("https://ipsidekick.com/{$ip}");
$json = json_decode($string);
return $json->country->name;
//These fields are available:
//return json->ip;
//return json->country->code;
//return json->country->name;
//return json->currency->code;
//return json->currency->decimals;
//return json->currency->name;
//return json->timeZone->gmtOffset;
//return json->timeZone->name;
//return json->holiday;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment