更新:我现在可以访问主页面,但我没有登录。
$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;
答案 0 :(得分:0)
添加curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
。
答案 1 :(得分:0)
curl_exec()
会返回false:
$content = curl_exec($ch);
if ($content === FALSE) {
die(curl_error($ch));
}
return($content);
答案 2 :(得分:0)
你需要做两件事。首先,将以下两个选项添加到CURL:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
这将告诉CURL遵循任何重定向。然后,改变返回echo。 Echo会将数据发送到浏览器。那你就定了!
答案 3 :(得分:0)
在所有光荣的回答之后......我把所有的一切都放在一起
$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);