diff options
author | dchill42 <dchill42@gmail.com> | 2012-07-31 15:41:01 +0200 |
---|---|---|
committer | dchill42 <dchill42@gmail.com> | 2012-07-31 15:41:01 +0200 |
commit | 7e92b7332ea4d28648e69eabcb93cead35dbca26 (patch) | |
tree | b7714536b89557129ed51fe675725fe28639c1e0 /system/core/Input.php | |
parent | 57486009573a86d9e286a49c92216ba17aae0d5a (diff) | |
parent | 3a2d573a96241c01124d15c1ce517078e07c6235 (diff) |
Merge branch 'develop' of github.com:/EllisLab/CodeIgniter into session
Diffstat (limited to 'system/core/Input.php')
-rw-r--r-- | system/core/Input.php | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/system/core/Input.php b/system/core/Input.php index 162e40c85..968a42a9a 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -330,10 +330,33 @@ class CI_Input { if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR')) { + $has_ranges = strpos($proxies, '/') !== false; $proxies = preg_split('/[\s,]/', config_item('proxy_ips'), -1, PREG_SPLIT_NO_EMPTY); $proxies = is_array($proxies) ? $proxies : array($proxies); + + if ($has_ranges) + { + $long_ip = ip2long($_SERVER['REMOTE_ADDR']); + $bit_32 = 1 << 32; + + // Go through each of the IP Addresses to check for and + // test against range notation + foreach($proxies as $ip) + { + list($address, $mask_length) = explode('/', $ip); + + // Generate the bitmask for a 32 bit IP Address + $bitmask = $bit_32 - (1 << (32 - (int)$mask_length)); + if (($long_ip & $bitmask) == $address) + { + $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; + break; + } + } - $this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; + } else { + $this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; + } } elseif ( ! $this->server('HTTP_CLIENT_IP') && $this->server('REMOTE_ADDR')) { |