0
我曾經在網站上使用curl登錄並顯示信息,但現在網站正在使用cloudflare。問題是我無法遵循重定向,因爲該網站使用JavaScript。PHP Curl錯誤重定向
我認爲它可以很簡單的解決,因爲我使用PHP捲曲在本地主機上,並在5秒消息「訪問例如之前檢查你的瀏覽器。」後轉到我:www.localhost/LINKOFTHEREDIRECT而不是去www.example.com/LINKOFTHEREDIRECT並向我顯示正確的網頁。
這裏是我的代碼:
<?php
$url0 = "http://example.com/login.php";
$url = "http://example.com/pageIwant.php";
$user_agent='Mozilla/5.0 (Windows NT 6.3; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0';
$options = array(
CURLOPT_USERAGENT => $user_agent, //set user agent
CURLOPT_COOKIESESSION => true, // enable cookies
CURLOPT_COOKIEFILE =>"C:/Program Files/XAMPP/htdocs/cp/cookies.txt", //set cookie file
CURLOPT_COOKIEJAR =>"C:/Program Files/XAMPP/htdocs/cp/cookies.txt", //set cookie jar
CURLOPT_CUSTOMREQUEST =>"GET", //set request type post or get
CURLOPT_POST =>false, //set to GET
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 20, // timeout on connect
CURLOPT_TIMEOUT => 20, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch0 = curl_init($url0);
curl_setopt_array($ch0, $options);
$content0 = curl_exec($ch0);
curl_close($ch0);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch);
$header = curl_getinfo($ch);
curl_close($ch);
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
echo $content; ?>
這裏是JavaScript:
<script type="text/javascript">
//<![CDATA[
(function() {
var a = function() {
try {
return !!window.addEventListener
} catch (e) {
return !1
}
},
b = function(b, c) {
a() ? document.addEventListener("DOMContentLoaded", b, c) : document.attachEvent("onreadystatechange", b)
};
b(function() {
var a = document.getElementById('cf-content');
a.style.display = 'block';
setTimeout(function() {
var t, r, a, f, YvDgwfU = {
"uxTkX": +((+!![] + []) + (!+[] + !![]))
};
t = document.createElement('div');
t.innerHTML = "<a href='/'>x</a>";
t = t.firstChild.href;
r = t.match(/https?:\/\//)[0];
t = t.substr(r.length);
t = t.substr(0, t.length - 1);
a = document.getElementById('jschl-answer');
f = document.getElementById('challenge-form');;
YvDgwfU.uxTkX *= +((!+[] + !![] + !![] + !![] + []) + (!+[] + !![] + !![] + !![]));
YvDgwfU.uxTkX -= +((+!![] + []) + (!+[] + !![] + !![] + !![] + !![] + !![] + !![]));
YvDgwfU.uxTkX -= +((!+[] + !![] + !![] + !![] + !![] + []) + (+[]));
a.value = parseInt(YvDgwfU.uxTkX, 10) + t.length;
f.submit();
}, 5850);
}, false);
})();
//]]>
</script>
你永遠不會得到cURL以任何開箱即用的方式遵循JavaScript重定向。你將不得不解析JavaScript的文件,並嘗試從那裏收集(如果可能)重定向將發送給你的地方。 – 2014-10-03 18:26:36