From 128e5e4a052de8f3d9e99bf18cf889902546019d Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 13 Aug 2008 01:43:49 +0000 Subject: [PATCH] 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 --- core/Session.php | 18 ++++++++++-------- core/control/HTTPRequest.php | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/core/Session.php b/core/Session.php index 9bb827c19..557543f6b 100644 --- a/core/Session.php +++ b/core/Session.php @@ -207,14 +207,16 @@ class Session { public static function load_config() { foreach(self::$session_ips as $sessionIP => $timeout) { if(preg_match('/^([0-9.]+)\s?-\s?([0-9.]+)$/', $sessionIP, $ips)) { - $startIP = ip2long($ips[1]); - $endIP = ip2long($ips[2]); - $clientIP = ip2long($_SERVER['REMOTE_ADDR']); - $minIP = min($startIP, $endIP); - $maxIP = max($startIP, $endIP); - - if($minIP <= $clientIP && $clientIP <= $maxIP) { - return self::set_timeout($timeout); + if(isset($_SERVER['REMOTE_ADDR'])) { + $startIP = ip2long($ips[1]); + $endIP = ip2long($ips[2]); + $clientIP = ip2long($_SERVER['REMOTE_ADDR']); + $minIP = min($startIP, $endIP); + $maxIP = max($startIP, $endIP); + + if($minIP <= $clientIP && $clientIP <= $maxIP) { + return self::set_timeout($timeout); + } } } // TODO - Net masks or something diff --git a/core/control/HTTPRequest.php b/core/control/HTTPRequest.php index eb74e2457..a0b15cbf9 100644 --- a/core/control/HTTPRequest.php +++ b/core/control/HTTPRequest.php @@ -349,7 +349,7 @@ class HTTPRequest extends Object implements ArrayAccess { } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //to check ip is pass from proxy return $_SERVER['HTTP_X_FORWARDED_FOR']; - } else { + } elseif(isset($_SERVER['REMOTE_ADDR'])) { return $_SERVER['REMOTE_ADDR']; } }