Skip to content

Commit

Permalink
Null coalescing for $_SERVER keys in iphandler_class.php
Browse files Browse the repository at this point in the history
Resolves CLI-invoked E_NOTICE in:
* eIPHandler::__construct()
* eIPHandler::getCurrentIP()

Also resolves possible blank eIPHandler::$serverIP
  • Loading branch information
Deltik committed Jan 17, 2020
1 parent c232613 commit bcba1e0
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions e107_handlers/iphandler_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function __construct($configDir = '')

$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);
Expand Down Expand Up @@ -334,7 +334,7 @@ private function getCurrentIP()
{
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))
Expand All @@ -344,10 +344,6 @@ private function getCurrentIP()
$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;
Expand Down

0 comments on commit bcba1e0

Please sign in to comment.