改进Request类的host方法 支持仅仅获取host而不包含端口号

This commit is contained in:
thinkphp
2018-04-27 17:13:25 +08:00
parent f4301c8667
commit 4c046575b6
3 changed files with 9 additions and 5 deletions

View File

@@ -1342,14 +1342,18 @@ class Request
/**
* 当前请求的host
* @access public
* @param bool $strict true 仅仅获取HOST
* @return string
*/
public function host()
public function host($strict = false)
{
if (isset($_SERVER['HTTP_X_REAL_HOST'])) {
return $_SERVER['HTTP_X_REAL_HOST'];
$host = $_SERVER['HTTP_X_REAL_HOST'];
} else {
$host = $this->server('HTTP_HOST');
}
return $this->server('HTTP_HOST');
return true === $strict ? strstr($host, ':', true) : $host;
}
/**