[英]php curl login issue (blank page)
更新:現在我可以訪問主頁了,但是我沒有登錄。
$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, 'emailAddress=jeffanderson@tradermail.info&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;
添加curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
。
如果存在問題, curl_exec()
返回false:
$content = curl_exec($ch);
if ($content === FALSE) {
die(curl_error($ch));
}
return($content);
您需要做兩件事。 首先,將以下兩個選項添加到CURL:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
這將告訴CURL遵循任何重定向。 然后,更改回顯。 Echo會將數據發送到瀏覽器。 然后,您都准備好了!
畢竟是光榮的回答。
$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, 'emailAddress=xxx@tradermail.info&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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.