比如客户端请求如下:
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应该怎么做呢?多谢。

解决方案 »

  1.   

    获得字段print_r(apache_request_headers());应该能找到,怎么在服务器端修改http请求头部信息,不懂了,Mark一下
      

  2.   


    $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);
      

  3.   

    <?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');