Skip to content

Instantly share code, notes, and snippets.

@rahuladams
Created June 18, 2020 13:49
Show Gist options
  • Save rahuladams/169bcbe7bc7e80652c140da0cfac722d to your computer and use it in GitHub Desktop.
Save rahuladams/169bcbe7bc7e80652c140da0cfac722d to your computer and use it in GitHub Desktop.
function getVisIpAddr() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
return $_SERVER['HTTP_CLIENT_IP'];
}
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else {
return $_SERVER['REMOTE_ADDR'];
}
}
function get_country(){
$vis_ip = getVisIPAddr();
$ipdat = @json_decode(file_get_contents( "http://www.geoplugin.net/json.gp?ip=" . $vis_ip));
return $ipdat->geoplugin_countryName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment