HTTP_HOST , SERVER_NAME 区别 php

 

当端口是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 @ 2021-07-19 09:55  林间有风-邓  阅读(221)  评论(0编辑  收藏  举报