Last active
July 10, 2017 12:41
-
-
Save digitalhuman/0c7fb45bcc2a73481cca3edaae98f52e to your computer and use it in GitHub Desktop.
Proper method getting your visitors IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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