當端口是80的時候,他們的內容是一樣的。
但是當端口不是80的時候,就不一樣了。
# HTTP_HOST = SERVER_NAME:SERVER_PORT
/**
* 獲取當前的host
*/
public static function getSelfHost() {
# HTTP_HOST = SERVER_NAME:SERVER_PORT
$host = 'http://'.$_SERVER['HTTP_HOST'].'/';
return $host;
}
/**
* 獲取當前的host
*/
public static function getHttpHost() {
if ((int)$_SERVER['SERVER_PORT'] === 80) {
$host = 'http://'.$_SERVER['SERVER_NAME'].'/';
} else {
$host = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].'/';
}
return $host;
}
上面的代碼功能一致 !!!