Skip to content

Instantly share code, notes, and snippets.

@LeonanCarvalho
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeonanCarvalho/01604a4102afe817d894 to your computer and use it in GitHub Desktop.
Save LeonanCarvalho/01604a4102afe817d894 to your computer and use it in GitHub Desktop.
Get client using ip address, works fine in intranet and DNS and reverse proxyes
$proxy = (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : false;
$hostname = "";
if (!!$proxy) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
$hostname .= "Proxy: ";
} else {
$ipaddress = $_SERVER['REMOTE_ADDR']; //
}
if ($ipaddress == $hostname) {
$hostname .= "Unknown";
} else {
$hostname .= gethostbyaddr($ipaddress);;
}
return $hostname;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment