Post cURL登录在cURL\u exec上挂起

Post cURL登录在cURL\u exec上挂起,post,curl,login,Post,Curl,Login,我正在尝试使用cURL登录一个网站。我的代码可以在其他网站上运行,但在这个网站上它挂在curl_exec上,致命错误:超过了30秒的最大执行时间 我知道有人问过类似的问题,我也看了所有的问题……我一直在尝试我能想到的剧本的每一个组合和修改,但运气不好。有什么建议吗 $username = 'myUsername'; $password = 'myPassword'; $url="https://www.centraldispatch.com/login/"; $cookie="cookie.

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

感谢Andrey帮助我找出问题出在我的wamp配置上,而不是脚本上。

对我的用户名起作用。但我认为第一次运行时可能不存在cookie文件。你为什么要检查它?我检查它是为了确保它不是引起问题的饼干。所以上面的代码对你来说没有问题(当然没有登录)?是的,它对我来说不适用。尽量不要使用CURLOPT_COOKIEFILE,只使用jar行。感谢您的反馈。我把我的脚本上传到另一台服务器上,它确实工作了,所以这一定是我本地wamp配置的问题……奇怪,因为我可以登录facebook和其他网站。再次感谢!