如何获取PHP的HTTP包头中的用户自定义部分?

自由之眼 2010-08-02 11:23:15
比如客户端请求如下:
POST /store/GetAllClass.php HTTP/1.1
Accept: */*
Referer: http://192.168.1.198/
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Content-Type: application/x-www-form-urlencoded
Host: 192.168.1.198
Request-Type: get_template_category
Content-Length: 0
Connection: close
Cache-Control: no-cache
我想在php里面获得Request-Type这个字段的数值,并在返回包头里面追加Request-Type这个字段,PHP应该怎么做呢?多谢。
...全文
249 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kyzy_yy_pm 2010-08-02
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 amani11 的回复:]
是,header就好了,傻BI了
[/Quote]哈哈
被糊弄了
amani11 2010-08-02
  • 打赏
  • 举报
回复
是,header就好了,傻BI了
CunningBoy 2010-08-02
  • 打赏
  • 举报
回复
<?php
$headers = apache_request_headers();

foreach ($headers as $header => $value) {
echo "$header: $value <br />\n";
}

echo $headers['Request-Type']; // 这个应该是你要的。
?>


如果要返回包头中追加,可以用
header('Request-Type: get_template_category');
Dleno 2010-08-02
  • 打赏
  • 举报
回复

$str="POST /store/GetAllClass.php HTTP/1.1
Accept: */*
Referer: http://192.168.1.198/
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Content-Type: application/x-www-form-urlencoded
Host: 192.168.1.198
Request-Type: get_template_category
Content-Length: 0
Connection: close
Cache-Control: no-cache";
$header=explode("\r\n",$str);
foreach($header as $key=>$value){
if(strpos($value,":")){
$hi = explode(":",$value);
$header[$hi[0]]=trim($hi[1]);
}else{
$hi = explode(" ",$value);
$header["Method"]=$hi[0];
$header["RequestURI"]=$hi[1];
}
unset($header[$key]);
}
print_r($header);
amani11 2010-08-02
  • 打赏
  • 举报
回复
获得字段print_r(apache_request_headers());应该能找到,

怎么在服务器端修改http请求头部信息,不懂了,Mark一下

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧