curl为什么无法模拟HTTP_X_REQUESTED_WITH呢?

hphper 发布于 2016/11/10 10:40
阅读 858
收藏 0

a.cn下的curl.php


<?php
 function request($url, $data = '',$agent= false) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    if($agent){
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)");
    }
    $header = [
        'X_REQUESTED_WITH:XMLHttpRequest',
        'a:XMLHttpRequest',
        'a1:XMLHttpRequest'
    ];
    curl_setopt ( $ch, CURLOPT_POST, TRUE );
    curl_setopt ( $ch, CURLOPT_POSTFIELDS,  $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 120);
    curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
    $result = curl_exec($ch);

    if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == '200') {
        curl_close($ch);
        return $result;
    }else{
        echo curl_getinfo($ch, CURLINFO_HTTP_CODE);
    }
    curl_close ( $ch );
    return NULL;
}

$url='http://b.cn/b.php';
$res=request($url);
echo $res;



b.cn下的b.php



<?php
echo "<pre>";
echo count($_SERVER);
echo "<br>";
print_r($_SERVER);



a.cn/curl.php执行结果


a和a1都可以模拟,为何

X_REQUESTED_WITH

不可以模拟呢


加载中
0
hphper
hphper
自己顶一下
0
zn123
zn123
抓包看一下, 有时候是 web server 给吃了 
hphper
hphper
在firebug下看一样没有
0
hphper
hphper
curl难道做不到吗
返回顶部
顶部