2011-03-11 145 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