自定义打印日志

PHP获取请求头实现如下

/**
 * 获取请求header
 *
 * @param $param
 * @return array|mixed
 */
function getRequestHeaders($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;
}


$sign = getRequestHeaders("X-Sign");
$headers = getRequestHeaders();
更新日期:
作者: qwding