php获取请求header

 /**
     * 获取请求header
     *
     */
    function getallheaders($param = null) {
        $headers = array();
        foreach ($_SERVER as $name => $value) {
            if (substr($name, 0, 5) == 'HTTP_') {
                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
            }
        }
        if($param != null){
            return $headers[$param];
        }
        return $headers;
    }

你可能感兴趣的:(php)