cURL登录挂起curl_exec

时间:2013-04-28 23:56:00

标签: post curl login

我正在尝试使用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);

1 个答案:

答案 0 :(得分:0)

感谢Andrey让我弄清楚问题出在我的wamp配置上,而不是脚本。

相关问题