Skip to content

Instantly share code, notes, and snippets.

@brianwebb01
Created January 30, 2017 02:02
Show Gist options
  • Save brianwebb01/13b5c832798a3664e3733b52fd45cb66 to your computer and use it in GitHub Desktop.
Save brianwebb01/13b5c832798a3664e3733b52fd45cb66 to your computer and use it in GitHub Desktop.
IP geolocation in PHP
<?php
$ip = "8.8.8.8";
$r = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
print_r($r);
/**************
stdClass Object
(
[ip] => 8.8.8.8
[hostname] => google-public-dns-a.google.com
[city] => Mountain View
[region] => California
[country] => US
[loc] => 37.3860,-122.0838
[org] => AS15169 Google Inc.
[postal] => 94035
)
**************/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment