Home » Php » php – Code works in postman but not in the script – 47-Maximum (20) redirects followed

php – Code works in postman but not in the script – 47-Maximum (20) redirects followed

Posted by: admin February 25, 2020 Leave a comment

Questions:

I created and tested one post request on postman and it gives me back correct page, but when I put this code inside my PHP it doesn’t work, I ‘ve got error:

47-Maximum (10) redirects followed

  $curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://xxxxx.com/login/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS =>"email=xxxx.xxxx%40mail.com&password=xxxxu&url=",
  CURLOPT_HTTPHEADER => array(
    "Content-Type:  application/x-www-form-urlencoded",
    "User-Agent:  Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Any help?

How to&Answers:

If you are using self signed certificate you should disable ssl check with curl.

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false).