public function getHttpHost() -> string
{
var host, strict, cleanHost;
let strict = this->strictHostCheck;
/**
* Get the server name from $_SERVER["HTTP_HOST"]
*/
let host = this->getServer("HTTP_HOST");
if !host {
/**
* Get the server name from $_SERVER["SERVER_NAME"]
*/
let host = this->getServer("SERVER_NAME");
if !host {
/**
* Get the server address from $_SERVER["SERVER_ADDR"]
*/
let host = this->getServer("SERVER_ADDR");
}
}
if host && strict {
/**
* Cleanup. Force lowercase as per RFC 952/2181
*/
let cleanHost = strtolower(
trim(host)
);
if memstr(cleanHost, ":") {
let cleanHost = preg_replace("/:[[:digit:]]+$/", "", cleanHost);
}
/**
* Host may contain only the ASCII letters 'a' through 'z'
* (in a case-insensitive manner), the digits '0' through '9', and
* the hyphen ('-') as per RFC 952/2181
*/
if unlikely ("" !== preg_replace("/[a-z0-9-]+\.?/", "", cleanHost)) {
throw new UnexpectedValueException("Invalid host " . host);
}
} else {
let cleanHost = host;
}
return (string) cleanHost;
}
/**
* Gets active server host or name
*
* @return string
*/
public function getHttpHost(): string
{
return $this->getServer('http_host') ?:
$this->getServerName();
}
/**
* Gets active server host
*
* @return string
*/
public function getHttpHost(): string
{
return $this->getServer('http_host') ?: '';
}