Created
March 5, 2015 15:13
-
-
Save ygerasimov/e59c470b57f903f14359 to your computer and use it in GitHub Desktop.
acquia ip_address()
This file contains hidden or 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
// Code provided by Acquia. | |
// Non balanced servers (dev and stage) don't have this problem. | |
if (!empty($conf['reverse_proxy_addresses'])) { | |
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); | |
$ips = array_map('trim', $ips); | |
// Add REMOTE_ADDR to the X-Forwarded-For list (the ip_address function will | |
// also do this) in case it's a 10. internal AWS address; if it is we should | |
// add it to the list of reverse proxy addresses so that ip_address will | |
// ignore it. | |
$ips[] = $_SERVER['REMOTE_ADDR']; | |
// Work backwards through the list of IPs, adding 10. addresses to the proxy | |
// // list but stop at the first non-10. address we find. | |
$ips = array_reverse($ips); | |
foreach ($ips as $ip) { | |
if (strpos($ip, '10.') === 0) { | |
if (!in_array($ip, $conf['reverse_proxy_addresses'])) { | |
$conf['reverse_proxy_addresses'][] = $ip; | |
} | |
} else { // we hit the first non-10. address, so stop. | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment