2011-03-11 147 views
0

更新:我现在能够访问主网页,但我没有登录PHP的卷曲登录问题(空白页)

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://www.xxx.com/?cmd=home'); 
curl_setopt ($ch, CURLOPT_POST, 1); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, '[email protected]&persist=on&pswd=qweqwe&from=/?cmd=home'); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
$content = curl_exec ($ch); 
curl_close ($ch); 

echo $content; 
+2

你不只是发表您的用户名和密码,是吗? – 2011-03-11 19:23:21

+0

是的,但它的帐户我不使用 – jennifer 2011-03-11 19:32:19

+0

您可能需要添加'curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,true);'如果他们的登录系统使用重定向。 – drudge 2011-03-11 19:34:00

回答

0

添加curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);

0

curl_exec()返回false如果出现了一个问题:

$content = curl_exec($ch); 
if ($content === FALSE) { 
     die(curl_error($ch)); 
} 
return($content); 
+0

@Marc B返回一个没有错误的空白页 – jennifer 2011-03-11 20:22:20

+0

尝试'curl_setopt($ ch,'CURLOPT_HEADER',true)',这将返回以及请求的主体。这应该有助于调试。 – 2011-03-11 20:31:32

+0

@Marc B什么也没发生,仍然是空白页。如果你没有太多的麻烦,你可以尝试使用swagbucks.com上的登录信息来创建一个curl脚本:email:[email protected]传递:qweqwe – jennifer 2011-03-11 20:46:51

0

你需要做两件事情。首先,将以下两个选项添加到CURL:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_MAXREDIRS, 3); 

这将告诉CURL遵循任何重定向。然后,将返回更改为回显。 Echo会将数据发送到浏览器。然后,你们都准备好了!

0

毕竟光荣answer..u把所有一起在下面的方式

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://www.xxx.com/?cmd=sb-login&from=/?cmd=home'); 
curl_setopt ($ch, CURLOPT_POST, 1); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, '[email protected]&persist=on&pswd=xxx&from=/?cmd=home'); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_MAXREDIRS, 10); 
$content = curl_exec($ch); 
if (FALSE===$content { 
     echo "Follwowing error:".curl_error(); 
     die(curl_errorno($ch)); 
} 
curl_close ($ch); 
return($content); 
+0

这有错误 – jennifer 2011-03-11 20:21:18

+0

错误!你会进一步解释吗? errorno? – diEcho 2011-03-13 20:29:04