Php 旁路内囊试验

Php 旁路内囊试验,php,curl,web-scraping,web-crawler,Php,Curl,Web Scraping,Web Crawler,我试图在一个使用Incapsula的网站上使用cURL更新我的状态。 我甚至不能访问主页,因为他们的JS测试安全。 我正在克隆我的头、用户代理、IP,但仍然得到了错误 那么有人能想出一种方法让cURL连接起来吗?以下是我的代码,适用于所有其他站点: function curl_redirect_exec($ch, &$redirects, $curlopt_header = false) { curl_setopt($ch, CURLOPT_HEADER, true);

我试图在一个使用Incapsula的网站上使用cURL更新我的状态。 我甚至不能访问主页,因为他们的JS测试安全。 我正在克隆我的头、用户代理、IP,但仍然得到了错误

那么有人能想出一种方法让cURL连接起来吗?以下是我的代码,适用于所有其他站点:

function curl_redirect_exec($ch, &$redirects, $curlopt_header = false) {
    curl_setopt($ch, CURLOPT_HEADER, true);
    //curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:' ) );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");
    $data = curl_exec($ch);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($http_code == 301 || $http_code == 302) {
        list($header) = explode("\r\n\r\n", $data, 2);
        $matches = array();
        preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
        $url = trim(array_pop($matches));
        $url_parsed = parse_url($url);
        if (isset($url_parsed)) {
            curl_setopt($ch, CURLOPT_URL, $url);
            $redirects++;
            return curl_redirect_exec($ch, $redirects);
        }
    }
    if ($curlopt_header)
        return $http_code.$data;
    else {
        list(,$body) = explode("\r\n\r\n", $data, 2);
        return $http_code.$body;
    }
}
function getPage($url,$post=false,$cookijs=false) {
if(!$cookijs) $cookijs = "pass=71c2bce341575e4312fcf19ce2a6eaa9;uid=1174461";
$cookie = tempnam ("/tmp/curlcookies", "CURLCOOKIE");
$timeout = 10;
 $ch = curl_init(); 
 curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_REFERER, 'http://www.enjin.com');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
    'Connection: keep-alive',
    'Keep-Alive: 300',
    "Accept-Language: en-US,en;q=0.5",
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
));
    curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
  #curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:' ) );
  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0");
curl_setopt($ch, CURLOPT_COOKIE, $cookijs);
 if((isset($post)) && ($post != false)) {
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }     
 $redirects=5000;
 $data = curl_redirect_exec($ch,$redirects);

 curl_close($ch);
 return $data;
}
$cookijs = array(
"incap_ses_151_48573 " => "eygjTe/9pTa4mxn7Vn0YAkzw51IAAAAAeowsmkMHrBX5eKy0Ejmh8g==",
"visid_incap_48573" => "4E8wP8B5QfKxV6UcDRpmXzHw51IAAAAAQkIPAAAAAACAeLthAV1yLUSyWQXQRO15b5GpU/fLrOMW"
);
$lapa = getPage("http://www.enjin.com", false, $cookijs
);
echo $lapa;

我建议你联系恩金,让他们把你的ip或其他东西列入白名单。。。
这会节省你的时间,无用的努力和被禁止。

这不能通过Curl来完成,因为Incapsula首先测试你的JS-JS在浏览器上执行,而Curl不能-你应该使用phyton或C#并创建一个批处理文件来接收你的状态和更新-然后你可以使用shell_exec来执行-如果你需要更多帮助,这对你很重要,请联系我们我