Skip to content

Instantly share code, notes, and snippets.

@ceylani
Last active December 2, 2016 08:31
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ceylani/a27a8a52f727df4b5cadc50470ea4430 to your computer and use it in GitHub Desktop.
Getting real IP address from gcloud HTTP LB
function getClientIP()
{
if ($_SERVER['HTTP_X_FORWARDED_FOR']) {
$ip_exp = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$c = count($ip_exp) - 2;
$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