2
我想在使用Incapsula的網站上使用cURL更新我的狀態。 因爲他們的JS測試安全性,我甚至無法訪問主頁面。 我克隆我的頭文件,useragent,IP,但仍然出現錯誤。Bypass Incapsula JStest
那麼任何人都可以想出一種方法來獲得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;
它不能通過Curl完成,因爲Incapsula首先測試你的JS - JS在瀏覽器上執行,而curl不能 - 你應該使用phyton或C#並創建一個批處理文件來接收你的狀態和更新 - 然後你可以使用shell_exec來執行它 - 如果你需要更多的幫助,這對你來說很重要。 –