Last active
December 2, 2016 08:31
-
-
Save ceylani/f891952bbcc2103660ff65854bccb34d to your computer and use it in GitHub Desktop.
Getting real IP address from AWS LB
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 getClientIP() | |
{ | |
if ($_SERVER['HTTP_X_FORWARDED_FOR']) { | |
$ip_exp = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); | |
$c = count($ip_exp) - 1; | |
$real_ip = trim($ip_exp[$c]); | |
return $_SERVER['REMOTE_ADDR'] = $real_ip; | |
} else { | |
return $_SERVER['REMOTE_ADDR']; | |
} | |
} | |
$client_ip = getClientIP(); | |
echo $client_ip; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment