HTTP_HOST , SERVER_NAME 区别

当端口是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;
}

上面的代码功能一致 !!!

posted @ 2019-06-15 14:35  TBHacker  阅读(5916)  评论(0编辑  收藏  举报