http请求的header中的os_,net_参数在 php $_SERVER 无法获取

客户端在请求时在http请求的header中加入了一些自定义参数,
但是以net_os_,device_开头的一些参数在后端无法获取到。
后端使用的 php,打印$_SERVER没有这些参数

看了http协议cgi协议也没有找到相关说明

不太明白怎么回事

阅读 5.2k
3 个回答

你试一下apache_request_headers() 函数 获取一下看能够获取到吗?

谢邀!

<?php
    header('Access-Control-Allow-Origin:*');  
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS');  
    header('Access-Control-Allow-Headers:WWW-Authenticate,Authorization,Set-Cookie,X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'); 
    
    // 获取头部信息end
    $header = apache_request_headers();
    
    // 取head标签内容
     var_Dump($header);exit;

?> 

获取的时候前面要HTTP_

$_SERVER['HTTP_Authorization']

找到原因了
不只是net_os_,device_开头的一些参数,默认情况下nginx会自动drop所有带下划线的header
需要设置 underscores_in_headers on;

If you do not explicitly set underscores_in_headers on;, nginx will silently drop HTTP headers with underscores (which are perfectly valid according to the HTTP standard). This is done in order to prevent ambiguities when mapping headers to CGI variables, as both dashes and underscores are mapped to underscores during that process.
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题