Skip to content

Instantly share code, notes, and snippets.

@digitalhuman
Last active July 10, 2017 12:41
Show Gist options
  • Save digitalhuman/0c7fb45bcc2a73481cca3edaae98f52e to your computer and use it in GitHub Desktop.
Save digitalhuman/0c7fb45bcc2a73481cca3edaae98f52e to your computer and use it in GitHub Desktop.
Proper method getting your visitors IP
// Function to get the client REMOTE IP address
function remote_addr() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
elseif (getenv('HTTP_X_REAL_IP')) {
$ipaddress = getenv('HTTP_X_REAL_IP');
}
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment