HTTP_HOST , SERVER_NAME 区别 php

时间:2021-07-19 14:38:50   收藏:0   阅读:14

 

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

 

原文:https://www.cnblogs.com/vip-deng-vip/p/15028878.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!