Returns the protocol + the current host + the port (if different than
common ports).

@return string $url
359009
public static function getSelfURLhost()
    {
        $currenthost = self::getSelfHost();

        $port = '';

        if (self::isHTTPS()) {
            $protocol = 'https';
        } else {
            $protocol = 'http';
        }

        $portnumber = self::getSelfPort();

        if (isset($portnumber) && ($portnumber != '80') && ($portnumber != '443')) {
            $port = ':' . $portnumber;
        }

        return $protocol."://" . $currenthost . $port;
    }
290939
public function getPort()
    {
        if (null !== $this->port) {
            return $this->port;
        }

        $tmp = parse_url($this->getUrl());
        if (isset($tmp['port'])) {
            $this->setPort($tmp['port']);
        } elseif (isset($tmp['scheme'])) {
            $this->setPort(self::$defaultPorts[$tmp['scheme']]);
        }

        return $this->port;
    }
800252
protected function _getHostFromUri()
    {
        $host  = $this->uri->getHost();
        $host .= $this->uri->getPort() ? ':' . $this->uri->getPort() : '';
        return $host;
    }
1142499
public function getHost() : ?string 
    {
        if ( ! $this->hasHost()) {
            $this->setHost($this->getDefaultHost());
        }
        return $this->host;
    }
1238525
public static function GetCurrentProtocol () {
		$https_flag = (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') || (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
		return $https_flag ? 'https' : 'http';
	}
622461
public static function current()
    {
        if (defined('PHPUNIT_RUNNING')) {
            return 'http://localhost';
        }

        $protocol = (isset($_SERVER['HTTPS']) && (strcasecmp($_SERVER['HTTPS'], 'on') === 0 || $_SERVER['HTTPS'] == 1)
            || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0)
            ? 'https://' : 'http://';

        return $protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    }
805108
public function getUrl()
    {
        $proto = $this->getUrlProto();
        $host = $this->getUrlHost();
        $port = $this->getUrlPort($proto);
        

        $url = $proto . '://' . $host;
        if (($proto == 'https' && $port != 443) || ($proto == 'http' && $port != 80)) {
            $url .= ':' . $port;
        }

        if (isset($_SERVER)) {
            $path = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
            $url .= $path;
        }

        if ($host == 'unknown') {
            $url = null;
        }

        return $url;
    }
213805
public function getDefaultPort()
    {
        if (!$this->hasDefaultPort()) throw new UrlException(sprintf(
            "No default port for URL '%s'",
            $this->_inputString
        ));

        $scheme = $this->getScheme();
        if ($scheme == 'http') return 80;
        elseif ($scheme == 'https') return 443;
        else throw new UrlException("No default port for scheme '$scheme'");
    }
33690
public function getFullUrl()
    {
        $isSecure = $this->isSecure();
        $srvProtocol = strtolower($this->server->get('SERVER_PROTOCOL'));
        $protocol = substr($srvProtocol, 0, strpos($srvProtocol, '/')).(($isSecure) ? 's' : '');
        $port = $this->getPort();
        $port = ((!$isSecure && $port != '80') || ($isSecure && $port != '443')) ? ":$port" : '';

        return $protocol.'://'.$this->getHost().$port.$this->server->get('REQUEST_URI');
    }
77520
public static function getURI()
    {
        $s = $_SERVER;
        $ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on');
        $sp = strtolower(array_get($s, 'SERVER_PROTOCOL', 'http://'));
        $protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');
        $port = array_get($s, 'SERVER_PORT', '80');
        $port = ((!$ssl && $port == '80') || ($ssl && $port == '443')) ? '' : ':' . $port;
        $host = (isset($s['HTTP_HOST']) ? $s['HTTP_HOST'] : array_get($s, 'SERVER_NAME', 'localhost'));
        $host = (strpos($host, ':') !== false) ? $host : $host . $port;

        return $protocol . '://' . $host;
    }
983600
protected function getCurrentUrl()
    {
        $schema = ((!empty($this->server['HTTPS']) && $this->server['HTTPS'] !== 'off') || (!empty($this->server['SERVER_PORT']) && $this->server['SERVER_PORT'] == 443)) ? 'https://' : 'http://';

        $host = isset($this->server['HTTP_HOST']) ? $this->server['HTTP_HOST'] : 'localhost';

        return $schema.$host.$this->server['REQUEST_URI'];
    }
1163554
public function getHostAndPort(): string
    {
        if ($this->myPort !== $this->myScheme->getDefaultPort()) {
            return $this->myHost . ':' . $this->myPort;
        }

        return $this->myHost->__toString();
    }
448389
protected function getCurrentUrl()
    {
        $server = $this->pool->getServer();

        // Check if someone has been messing with the $_SERVER, to prevent
        // warnings and notices.
        if (empty($server) === true ||
            empty($server['SERVER_PROTOCOL']) === true ||
            empty($server['SERVER_PORT']) === true ||
            empty($server['SERVER_NAME']) === true ||
            empty($server['REQUEST_URI']) === true
        ) {
            return 'n/a';
        }

        // SSL or no SSL.
        $ssl = (!empty($server['HTTPS']) && $server['HTTPS'] === 'on');

        $protocol = strtolower($server['SERVER_PROTOCOL']);
        $protocol = substr($protocol, 0, strpos($protocol, '/'));
        if ($ssl === true) {
            $protocol .= 's';
        }

        $port = $server['SERVER_PORT'];

        if (($ssl === false && $port === '80') || ($ssl === true && $port === '443')) {
            // Normal combo with port and protocol.
            $port = '';
        } else {
            // We have a special port here.
            $port = ':' . $port;
        }

        if (isset($server['HTTP_HOST']) === true) {
            $host = $server['HTTP_HOST'];
        } else {
            $host = $server['SERVER_NAME'] . $port;
        }

        return $this->pool->encodingService->encodeString($protocol . '://' . $host . $server['REQUEST_URI']);
    }
858641
protected function getBaseUrl()
    {
        $port = '';
        if ($this->requestContext->getScheme() === 'https' && $this->requestContext->getHttpsPort() != 443) {
            $port = ":{$this->requestContext->getHttpsPort()}";
        }

        if ($this->requestContext->getScheme() === 'http' && $this->requestContext->getHttpPort() != 80) {
            $port = ":{$this->requestContext->getHttpPort()}";
        }

        $baseUrl = $this->requestContext->getBaseUrl();
        if (substr($this->requestContext->getBaseUrl(), -4) === '.php') {
            $baseUrl = pathinfo($this->requestContext->getBaseurl(), PATHINFO_DIRNAME);
        }
        $baseUrl = rtrim($baseUrl, '/\\');

        return sprintf(
            '%s://%s%s%s',
            $this->requestContext->getScheme(),
            $this->requestContext->getHost(),
            $port,
            $baseUrl
        );
    }
1047648
protected function vhost()
	{
		if (isset($_SERVER['HTTP_X_FORWARDED_HOST']))
		{
			return preg_replace('/[^A-Za-z0-9\[\]\.:-]/', '', rtrim($_SERVER['HTTP_X_FORWARDED_HOST'],'/'));
		}
		
		$host = rtrim($_SERVER['HTTP_HOST']);
		if ($host == '')
		{
			$host = rtrim($_SERVER['SERVER_NAME']);
		}
		$host  = preg_replace('/[^A-Za-z0-9\[\]\.:-]/', '', $host);
		return $host;
	}
829181
protected function getCurrentUrl() {
    $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'
      ? 'https://'
      : 'http://';
    $currentUrl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    $parts = parse_url($currentUrl);

    // drop known fb params
    $query = '';
    if (!empty($parts['query'])) {
      $params = array();
      parse_str($parts['query'], $params);
      foreach(self::$DROP_QUERY_PARAMS as $key) {
        unset($params[$key]);
      }
      if (!empty($params)) {
        $query = '?' . http_build_query($params, null, '&');
      }
    }

    // use port if non default
    $port =
      isset($parts['port']) &&
      (($protocol === 'http://' && $parts['port'] !== 80) ||
       ($protocol === 'https://' && $parts['port'] !== 443))
      ? ':' . $parts['port'] : '';

    // rebuild
    return $protocol . $parts['host'] . $port . $parts['path'] . $query;
  }
224026
public function getHostRelativeUrl()
    {
        $url = $this->getPath();
        if ($this->hasQueryString()) $url .= '?' . $this->getQueryString();
        if ($this->hasFragmentString()) $url .= '#' . $this->getFragmentString();
        return $url;
    }