Last active
December 2, 2016 08:31
-
-
Save ceylani/a27a8a52f727df4b5cadc50470ea4430 to your computer and use it in GitHub Desktop.
Getting real IP address from gcloud HTTP 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) - 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