php 获取host地址

/**
     * HTTP_HOST = SERVER_NAME:SERVER_PORT
     * 获取当前的host
     */
    public static function getSelfHost() {
        setlog($_SERVER,$_SERVER['HTTP_HOST'],$_SERVER['SERVER_NAME'],'server.log');

        $port = $_SERVER['SERVER_PORT'];
        $http_host = $_SERVER['HTTP_HOST'];
        if ($port == 80 || $port == 443) {
            $host = 'http://' . $http_host . '/';
        } else {
            $host = 'http://'. $http_host .':'.$port.'/';
        }


//        $host = 'http://' . $http_host . '/';
        return $host;
    }
posted @ 2021-12-06 12:03  TBHacker  阅读(982)  评论(0编辑  收藏  举报