Php卷曲问题

时间:2011-01-25 18:42:38

标签: php curl

<?php
set_time_limit(0);
$php_userid = "my yahoo id";
$php_password = "my yahoo password";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
$reffer = "http://mail.yahoo.com/";
$LOGINURL = "https://login.yahoo.com/config/login?";
$POSTFIELDS = ".tries=1&.src=ym&.intl=us&.u=3jtlosl6ju4sc.v=0&.challenge=NZYhS1spj7zunoVhpd6KRNqaF5Kz&hasMsgr=0&.chkP=Y&.done=http://mail.yahoo.com&.pd=ym_ver=0&c=&ivt=&sg=&pad=3&aad=3&login".$php_userid."&passwd".$php_password."";
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
$result = curl_exec ($ch);
curl_close ($ch); 
echo $result;
?>

有错误吗?我做错了什么,但我找不到。如果你能看到我的错误在哪里,请告诉我?我需要设置这个卷曲类。

4 个答案:

答案 0 :(得分:3)

POST数据格式错误,应为:

[...]  "login=" . urlencode($php_userid). "&passwd=" . urlencode($php_password) . ""

而不是

[...]  "login".$php_userid."&passwd".$php_password.""

您应该使用urlencode来确保POST数据中传递的数据已正确发送,并且您在登录和密码值中缺少=

答案 1 :(得分:2)

您应该使用curl_error来确定cURL过程中失败的内容。您可以在此处查看cURL错误代码列表:http://curl.haxx.se/libcurl/c/libcurl-errors.html

$result = curl_exec($ch);
$error = curl_error($ch);
print $error;
curl_close ($ch); 

答案 2 :(得分:0)

我假设.challenge字段是动态生成的。您的curl请求使用无效的质询,因此服务器会阻止它。

答案 3 :(得分:0)

  1. $cookie = cookie.txt";
  2. curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); this: curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
  3. 之后插入