From 7b682ae9f88bd953212281aadfbb4dd4dc0adbde Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 29 Jul 2007 21:04:03 +0000 Subject: - Patch #162944 by profix898: cleanup ip_address() code. --- includes/bootstrap.inc | 18 ++++++------------ 1 file 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; } -- cgit v1.2.3