简体   繁体   中英

php curl login issue (blank page)

UPDATE: I am now able to to access the main homepage, but i am not logged in.

$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;

Add curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); .

curl_exec() returns false if there was a problem:

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

You need to do two things. First, add the following two options to CURL:

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

That will tell CURL to follow any redirects. Then, change return to echo. Echo will send the data to the browser. Then you are all set!

after all honorable answer..u put all together in below way

$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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM