Add checks to see if REMOTE_ADDR is set before making use of it.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60578 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-08-13 01:43:49 +00:00
parent 48b60fa710
commit 128e5e4a05
2 changed files with 11 additions and 9 deletions

View File

@ -207,6 +207,7 @@ class Session {
public static function load_config() { public static function load_config() {
foreach(self::$session_ips as $sessionIP => $timeout) { foreach(self::$session_ips as $sessionIP => $timeout) {
if(preg_match('/^([0-9.]+)\s?-\s?([0-9.]+)$/', $sessionIP, $ips)) { if(preg_match('/^([0-9.]+)\s?-\s?([0-9.]+)$/', $sessionIP, $ips)) {
if(isset($_SERVER['REMOTE_ADDR'])) {
$startIP = ip2long($ips[1]); $startIP = ip2long($ips[1]);
$endIP = ip2long($ips[2]); $endIP = ip2long($ips[2]);
$clientIP = ip2long($_SERVER['REMOTE_ADDR']); $clientIP = ip2long($_SERVER['REMOTE_ADDR']);
@ -217,6 +218,7 @@ class Session {
return self::set_timeout($timeout); return self::set_timeout($timeout);
} }
} }
}
// TODO - Net masks or something // TODO - Net masks or something
} }
} }

View File

@ -349,7 +349,7 @@ class HTTPRequest extends Object implements ArrayAccess {
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//to check ip is pass from proxy //to check ip is pass from proxy
return $_SERVER['HTTP_X_FORWARDED_FOR']; return $_SERVER['HTTP_X_FORWARDED_FOR'];
} else { } elseif(isset($_SERVER['REMOTE_ADDR'])) {
return $_SERVER['REMOTE_ADDR']; return $_SERVER['REMOTE_ADDR'];
} }
} }