Skip to content

Instantly share code, notes, and snippets.

@CrBoy
Created November 20, 2013 03:49
Show Gist options
  • Save CrBoy/7557403 to your computer and use it in GitHub Desktop.
Save CrBoy/7557403 to your computer and use it in GitHub Desktop.
<?php
$keys = ['REMOTE_ADDR', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR'];
foreach ($keys as $key) {
$ip = $_SERVER[$key];
echo $key . ' = ' . $ip;
if ($ip != ''){
$location = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));
if($location){
echo ' (' . $location->geoplugin_city . ', ' . $location->geoplugin_countryName . ')';
}
}
echo '<br>' . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment