Tries to detect the host name of the server.

Some elements adapted from

@see https://github.com/symfony/HttpFoundation/blob/master/Request.php

@return string
166082
public function getHost(bool $withPort = true) : string
  {
      // Check for proxy first
      if ($host = $this->server('HTTP_X_FORWARDED_HOST')) {
          $host = last(explode(',', $host));
      } elseif (!$host = $this->server('HTTP_HOST')) {
          if (!$host = $this->server('HTTP_SERVER_NAME')) {
              $host = $this->server('HTTP_SERVER_ADDR');
          }
      }

      // trim and remove port number from host
      // host is lowercase as per RFC 952/2181
      $host = strtolower(preg_replace('/:\d+$/', '', trim($host)));

      if (!$withPort) {
          return $host;
      }

      // Port number
      $scheme = $this->getHttpScheme();
      $port = $this->getPort();
      
      $appendPort = ':' . $port;

      // Don't append port number if a normal port.
      if (($scheme == 'http' && $port == '80') || ($scheme == 'https' && $port == '443')) {
          $appendPort = '';
      }

      return $host . $appendPort;
  }
1328064
public static function getHostUri()
  {
    $sheme = (self::getHostParam("HTTPS") == "on") ? "https" : "http";

    $serverName = new Str(self::getHostParam("HTTP_HOST"));
    $serverPort = self::getHostParam("SERVER_PORT");
    $serverPort = ($serverPort != 80 && $serverPort != 443) ? ":" . $serverPort : "";

    if($serverName->endsWith($serverPort))
    {
      $serverName = $serverName->replace($serverPort, "");
    }

    return new Str($sheme . "://" . $serverName . $serverPort);
  }
1276290
public function toString()
   {
      if ( empty( $this->_hostName ) )
      {
         if ( \is_null( $this->_tld ) )
         {
            return '';
         }
         return $this->_tld->toString();
      }
      if ( \is_null( $this->_tld ) )
      {
         return $this->_hostName;
      }
      return $this->_hostName . '.' . $this->_tld->toString();
   }
600896
public static function getHostname($requestHost = TRUE) {
		$host = '';
			// If not called from the command-line, resolve on getIndpEnv()
			// Note that TYPO3_REQUESTTYPE is not used here as it may not yet be defined
		if ($requestHost && (!defined('TYPO3_cliMode') || !TYPO3_cliMode)) {
			$host = self::getIndpEnv('HTTP_HOST');
		}
		if (!$host) {
				// will fail for PHP 4.1 and 4.2
			$host = @php_uname('n');
				// 'n' is ignored in broken installations
			if (strpos($host, ' ')) {
				$host = '';
			}
		}
			// we have not found a FQDN yet
		if ($host && strpos($host, '.') === FALSE) {
			$ip = gethostbyname($host);
				// we got an IP address
			if ($ip != $host) {
				$fqdn = gethostbyaddr($ip);
				if ($ip != $fqdn) {
					$host = $fqdn;
				}
			}
		}
		if (!$host) {
			$host = 'localhost.localdomain';
		}

		return $host;
	}
1356167
public function getClientIp(): string {
        $s = $this->server();
        if (array_key_exists('HTTP_CLIENTIP', $s)) {
            if (!empty($s['HTTP_CLIENTIP'])) {
                return $s['HTTP_CLIENTIP'];
            }
        }
        if (array_key_exists('HTTP_X_FORWARDED_FOR', $s) && !empty($s['HTTP_X_FORWARDED_FOR'])) {
            $addresses = explode(',', $s['HTTP_X_FORWARDED_FOR']);
            while (count($addresses)) {
                $ip = @trim(array_shift($addresses));
                if ($ip === '') {
                    continue;
                }
                if (!self::isLanIp($ip)) {
                    return $ip;
                }
            }
        }
        return $s['REMOTE_ADDR'];
    }
1142499
public function getHost() : ?string 
    {
        if ( ! $this->hasHost()) {
            $this->setHost($this->getDefaultHost());
        }
        return $this->host;
    }
531453
public function getClientIP(): string
    {
        $ip = $this->getServerParam('REMOTE_ADDR');

        if ($this->getServerParam('HTTP_X_FORWARDED_FOR') !== null) {
            $ip = $this->getServerParam('HTTP_X_FORWARDED_FOR');
        }

        if ($this->getServerParam('HTTP_CLIENT_IP') !== null) {
            $ip = $this->getServerParam('HTTP_CLIENT_IP');
        }

        if ($this->headers->has('X-Real-Ip')) {
            $ip = $this->getHeaderLine('X-Real-Ip');
        }

        if ($this->headers->has('X-Client-Ip')) {
            $ip = $this->getHeaderLine('X-Client-Ip');
        }

        return is_null($ip) ? 'Unknow' : $ip;
    }
226310
public static function getHttpHost():string
    {
        static $hostname = null;
        
        if (!$hostname) {
            $http = filter_input(INPUT_SERVER, 'HTTPS') ? 'https://' : 'http://';
            $hostname = $http . filter_input(INPUT_SERVER, 'HTTP_HOST');
        }
        return $hostname;
    }
626568
private function _hostname()
    {
        if (PSI_USE_VHOST === true) {
            if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
        } else {
            $buffer = $this->_get_Win32_ComputerSystem();
            if (!$buffer && CommonFunctions::executeProgram('reg', 'query HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName /v ComputerName', $strBuf, false) && (strlen($strBuf) > 0) && preg_match("/^\s*ComputerName\s+REG_SZ\s+(\S+)\s*$/mi", $strBuf, $buffer2)) {
                    $buffer[0]['Name'] = $buffer2[1];
            }
            if ($buffer) {
                $result = $buffer[0]['Name'];
                $ip = gethostbyname($result);
                if ($ip != $result) {
                    if ((version_compare("10.0.0.0", $ip, "<=") && version_compare($ip, "10.255.255.255", "<=")) ||
                        (version_compare("172.16.0.0", $ip, "<=") && version_compare($ip, "172.31.255.255", "<=")) ||
                        (version_compare("192.168.0.0", $ip, "<=") && version_compare($ip, "192.168.255.255", "<=")) ||
                        (version_compare("127.0.0.0", $ip, "<=") && version_compare($ip, "127.255.255.255", "<=")) ||
                        (version_compare("169.254.1.0", $ip, "<=") && version_compare($ip, "169.254.254.255", "<=")) ||
                        (version_compare("255.255.255.255", $ip, "=="))) {
                        $this->sys->setHostname($result); // internal ip
                    } else {
                        $this->sys->setHostname(gethostbyaddr($ip));
                    }
                }
            } else {
                if (CommonFunctions::readenv('COMPUTERNAME', $hnm)) $this->sys->setHostname($hnm);
            }
        }
    }
225182
public function getHost()
    {
        $host = $this->headers->get('HTTP_HOST');
        if ($host) {
            if (strpos($host, ':') !== false) {
                $hostParts = explode(':', $host);

                return $hostParts[0];
            }

            return $host;
        }

        return $this->env->get('SERVER_NAME');
    }
1306364
public static function serverURL()
    {
        $host = self::hostname();
        $url = '';
        if ( $host )
        {
            if ( self::isSSLNow() )
            {
                // https case
                $host = preg_replace( '/:\d+$/', '', $host );

                $ini = eZINI::instance();
                $sslPort = $ini->variable( 'SiteSettings', 'SSLPort' );

                $sslPortString = ( $sslPort == eZSSLZone::DEFAULT_SSL_PORT ) ? '' : ":$sslPort";
                $url = "https://" . $host  . $sslPortString;
            }
            else
            {
                $url = "http://" . $host;
            }
        }
        return $url;
    }
1215270
public function getHost() {
		if (!is_null($this->host)) {
			return $this->host;
		}

		if ($_SERVER['HTTP_X_FORWARDED_HOST']) {
			$elements = explode(',', $value);
			$host = trim(end($elements));
		} else if ($_SERVER['HTTP_HOST']) {
			$host = $_SERVER['HTTP_HOST'];
		} else if ($_SERVER['SERVER_NAME']) {
			$host = $_SERVER['SERVER_NAME'];
		}

		if (isset($host)) {
			$host = preg_replace('/:\d+$/', '', $host);
			$this->host = $host;
		}

		return $this->host;
	}
33265
public static function getHostname()
    {
        // Check trusted requires config file which is not ready yet
        $host = Url::getHost($checkIfTrusted = false);

        // Remove any port number to get actual hostname
        $host = Url::getHostSanitized($host);

        return $host;
    }
336952
public static function hostname()
    {
        $hostName = null;
        $forwardedHostsString = self::serverVariable( 'HTTP_X_FORWARDED_HOST', true );
        if ( $forwardedHostsString )
        {
            $forwardedHosts = explode( ',', $forwardedHostsString );
            $hostName = trim( $forwardedHosts[0] );
        }

        if ( !$hostName && self::serverVariable( 'HTTP_HOST', true ) )
        {
            $hostName = self::serverVariable( 'HTTP_HOST' );
        }

        if ( !$hostName )
        {
            $siteUrl = eZINI::instance()->variable( 'SiteSettings', 'SiteURL' );
            $hostName = parse_url( "http://{$siteUrl}", PHP_URL_HOST );
        }

        return $hostName;
    }
800252
protected function _getHostFromUri()
    {
        $host  = $this->uri->getHost();
        $host .= $this->uri->getPort() ? ':' . $this->uri->getPort() : '';
        return $host;
    }
711327
public static function fullServerName()
    {
        //$protocol = ($_SERVER['SERVER_PORT'] == '443') ? 'https://' : 'http://';
        $protocol = $_SERVER['REQUEST_SCHEME'] . '://';

        if ( isset($_SERVER['HTTP_X_FORWARDED_SERVER']) ) {
            $host = $_SERVER['HTTP_X_FORWARDED_SERVER'];
        } else {
            $host = $_SERVER['SERVER_NAME'] ?? '';
        }

        $port = ($_SERVER['SERVER_PORT'] == 80) ? '' : ":{$_SERVER['SERVER_PORT']}";

        return $protocol . $host . $port;
    }
110555
public static function hostName(HTTPRequest $request = null)
    {
        $host = static::host($request);
        return parse_url($host, PHP_URL_HOST) ?: null;
    }