public static function root($addAuth = false)
{
$url = '';
// Check to see if it's over https
$isHttps = self::isHttps();
// Was a username or password passed?
if ($addAuth) {
$url .= self::getAuth();
}
// We want the user to stay on the same host they are currently on,
// but beware of security issues
// see http://shiflett.org/blog/2006/mar/server-name-versus-http-host
$host = Arr::key('HTTP_HOST', $_SERVER, true);
$port = Arr::key('SERVER_PORT', $_SERVER, true);
$url .= str_replace(':' . $port, '', $host);
// Is it on a non standard port?
if ($isHttps && $port != self::PORT_HTTPS) {
$url .= Arr::key('SERVER_PORT', $_SERVER) ? ':' . $_SERVER['SERVER_PORT'] : '';
} elseif (!$isHttps && $port != self::PORT_HTTP) {
$url .= Arr::key('SERVER_PORT', $_SERVER) ? ':' . $_SERVER['SERVER_PORT'] : '';
}
if ($url) {
if ($isHttps) {
return 'https://' . $url;
} else {
return 'http://' . $url;
}
}
return null;
}