Handle when SERVER['HTTP_HOST'] is not set

This commit is contained in:
Isaac Connor 2021-10-05 19:49:37 -04:00
parent 7f09cddcd7
commit a465403c72
1 changed files with 12 additions and 9 deletions

View File

@ -30,15 +30,16 @@ class Server extends ZM_Object {
return ZM_Object::_find_one(get_class(), $parameters, $options); return ZM_Object::_find_one(get_class(), $parameters, $options);
} }
public function Hostname( $new = null ) { public function Hostname($new = null) {
if ( $new != null ) if ($new != null)
$this->{'Hostname'} = $new; $this->{'Hostname'} = $new;
if ( isset( $this->{'Hostname'}) and ( $this->{'Hostname'} != '' ) ) { if (isset( $this->{'Hostname'}) and ($this->{'Hostname'} != '')) {
return $this->{'Hostname'}; return $this->{'Hostname'};
} else if ( $this->Id() ) { } else if ( $this->Id() ) {
return $this->{'Name'}; return $this->{'Name'};
} }
if (isset($_SERVER['HTTP_HOST'])) {
# This theoretically will match ipv6 addresses as well # This theoretically will match ipv6 addresses as well
if ( preg_match( '/^(\[[[:xdigit:]:]+\]|[^:]+)(:[[:digit:]]+)?$/', $_SERVER['HTTP_HOST'], $matches ) ) { if ( preg_match( '/^(\[[[:xdigit:]:]+\]|[^:]+)(:[[:digit:]]+)?$/', $_SERVER['HTTP_HOST'], $matches ) ) {
return $matches[1]; return $matches[1];
@ -47,6 +48,8 @@ class Server extends ZM_Object {
$result = explode(':', $_SERVER['HTTP_HOST']); $result = explode(':', $_SERVER['HTTP_HOST']);
return $result[0]; return $result[0];
} }
return '';
}
public function Protocol( $new = null ) { public function Protocol( $new = null ) {
if ( $new != null ) if ( $new != null )