From bcba1e065fe879011bb6d743c78e564fd32fdc88 Mon Sep 17 00:00:00 2001 From: Nick Liu Date: Fri, 17 Jan 2020 15:11:45 +0100 Subject: [PATCH] Null coalescing for $_SERVER keys in iphandler_class.php Resolves CLI-invoked E_NOTICE in: * eIPHandler::__construct() * eIPHandler::getCurrentIP() Also resolves possible blank eIPHandler::$serverIP --- e107_handlers/iphandler_class.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/e107_handlers/iphandler_class.php b/e107_handlers/iphandler_class.php index 76d3405fd..a14a5a206 100644 --- a/e107_handlers/iphandler_class.php +++ b/e107_handlers/iphandler_class.php @@ -171,7 +171,7 @@ class eIPHandler $this->ourIP = $this->ipEncode($this->getCurrentIP()); - $this->serverIP = $this->ipEncode($_SERVER['SERVER_ADDR']); + $this->serverIP = $this->ipEncode(isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : 'x.x.x.x'); $this->makeUserToken(); $ipStatus = $this->checkIP($this->ourIP); @@ -334,7 +334,7 @@ class eIPHandler { if(!$this->ourIP) { - $ip = $_SERVER['REMOTE_ADDR']; + $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'x.x.x.x'; if ($ip4 = getenv('HTTP_X_FORWARDED_FOR')) { if (!$this->isAddressRoutable($ip)) @@ -344,10 +344,6 @@ class eIPHandler $this->logBanItem(0, 'X_Forward '.$ip4.' --> '.$ip); // Just log for interest ATM } } - if($ip == '') - { - $ip = 'x.x.x.x'; - } $this->ourIP = $this->ipEncode($ip); // Normalise for storage } return $this->ourIP;