SimpleSAML\Utils\HTTP::getServerHost PHP Method

getServerHost() private static method

Retrieve Host value from $_SERVER environment variables.
Author: Olav Morken, UNINETT AS ([email protected])
private static getServerHost ( ) : string
return string The current host name, including the port if needed. It will use localhost when unable to determine the current host.
    private static function getServerHost()
    {
        if (array_key_exists('HTTP_HOST', $_SERVER)) {
            $current = $_SERVER['HTTP_HOST'];
        } elseif (array_key_exists('SERVER_NAME', $_SERVER)) {
            $current = $_SERVER['SERVER_NAME'];
        } else {
            // almost certainly not what you want, but...
            $current = 'localhost';
        }
        if (strstr($current, ":")) {
            $decomposed = explode(":", $current);
            $port = array_pop($decomposed);
            if (!is_numeric($port)) {
                array_push($decomposed, $port);
            }
            $current = implode($decomposed, ":");
        }
        return $current;
    }