我正在尝试使用 cURL 登录网站。我的代码可以在其他网站上运行,但是在这个网站上它挂在 curl_exec 上,致命错误:超过 30 秒的最大执行时间。
我知道有人问过类似的问题,而且我都看过了……我一直在尝试我能想到的脚本的所有组合和修改,但没有运气。有什么建议么?
$username = 'myUsername';
$password = 'myPassword';
$url="https://www.centraldispatch.com/login/";
$cookie="cookie.txt";
if (! file_exists($cookie) || ! is_writable($cookie))
{
echo 'Cookie file missing or not writable.';
exit;
}
$postFields = array(
'Username' => $username,
'Password' => $password,
'r' => '' //a hidden field in the form
);
$postdata = http_build_query($postFields);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch); //code hangs here
echo $result;
curl_close($ch);