From a465403c72e620e7ac6666faac4da41991a04d91 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 5 Oct 2021 19:49:37 -0400 Subject: [PATCH] Handle when SERVER['HTTP_HOST'] is not set --- web/includes/Server.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/web/includes/Server.php b/web/includes/Server.php index bf3dfeb51..f976a4236 100644 --- a/web/includes/Server.php +++ b/web/includes/Server.php @@ -30,22 +30,25 @@ class Server extends ZM_Object { return ZM_Object::_find_one(get_class(), $parameters, $options); } - public function Hostname( $new = null ) { - if ( $new != null ) + public function Hostname($new = null) { + if ($new != null) $this->{'Hostname'} = $new; - if ( isset( $this->{'Hostname'}) and ( $this->{'Hostname'} != '' ) ) { + if (isset( $this->{'Hostname'}) and ($this->{'Hostname'} != '')) { return $this->{'Hostname'}; } else if ( $this->Id() ) { return $this->{'Name'}; } - # This theoretically will match ipv6 addresses as well - if ( preg_match( '/^(\[[[:xdigit:]:]+\]|[^:]+)(:[[:digit:]]+)?$/', $_SERVER['HTTP_HOST'], $matches ) ) { - return $matches[1]; - } + if (isset($_SERVER['HTTP_HOST'])) { + # This theoretically will match ipv6 addresses as well + if ( preg_match( '/^(\[[[:xdigit:]:]+\]|[^:]+)(:[[:digit:]]+)?$/', $_SERVER['HTTP_HOST'], $matches ) ) { + return $matches[1]; + } - $result = explode(':', $_SERVER['HTTP_HOST']); - return $result[0]; + $result = explode(':', $_SERVER['HTTP_HOST']); + return $result[0]; + } + return ''; } public function Protocol( $new = null ) {