diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-07-29 21:04:03 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-07-29 21:04:03 +0000 |
commit | 7b682ae9f88bd953212281aadfbb4dd4dc0adbde (patch) | |
tree | 73263c2e2cc03a24db09de1dd2bffde98714212c /includes | |
parent | 80ff5109a774a69473e2a9d74a49b8dc4da03e8f (diff) | |
download | brdo-7b682ae9f88bd953212281aadfbb4dd4dc0adbde.tar.gz brdo-7b682ae9f88bd953212281aadfbb4dd4dc0adbde.tar.bz2 |
- Patch #162944 by profix898: cleanup ip_address() code.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/bootstrap.inc | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 52bfc5fa5..51ce58480 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -1077,7 +1077,6 @@ function language_default($property = NULL) { return $property ? $language->$property : $language; } - /** * If Drupal is behind a reverse proxy, we use the X-Forwarded-For header * instead of $_SERVER['REMOTE_ADDR'], which would be the IP address @@ -1087,20 +1086,15 @@ function language_default($property = NULL) { * IP address of client machine, adjusted for reverse proxy. */ function ip_address() { - static $remote_ip; + static $ip_address = NULL; - if ($remote_ip) { - // We have been here before, so just return the one we processed before - return $remote_ip; - } - else { - $remote_ip = $_SERVER['REMOTE_ADDR']; - if (variable_get('reverse_proxy', FALSE) && array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { - $ip_array = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); + if (!isset($ip_address)) { + $ip_address = $_SERVER['REMOTE_ADDR']; + if (variable_get('reverse_proxy', 0) && array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { // If there are several arguments, the leftmost one is the farthest client - $remote_ip = $ip_array[0]; + list($ip_address, ) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); } } - return $remote_ip; + return $ip_address; } |