Skip to content

Instantly share code, notes, and snippets.

@ceylani
Last active December 2, 2016 08:31
Show Gist options
  • Save ceylani/f891952bbcc2103660ff65854bccb34d to your computer and use it in GitHub Desktop.
Save ceylani/f891952bbcc2103660ff65854bccb34d to your computer and use it in GitHub Desktop.
Getting real IP address from AWS LB
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