0

I have these code to view pdf file using PHP language.

But my PDF file is in another remote server this server have HTTPS.

Below code is to call the pdf file.

It works for HTTP. But for HTTPS, failed to load the document.

Php file

$cookie = 'cookies.txt';
$timeout = 30; 
$url = "https://www.test.com/viewpdf/view.pdf";

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_PROXY, true);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);


header('Content-type: application/pdf');
$result = curl_exec($ch);
curl_close($ch);
echo $result; 

What am I missing here ?

Appreciate if someone can help me.

Thanks.

Rzj Hayabusa
  • 657
  • 2
  • 11
  • 29

1 Answers1

-1

If you are working on live server, then your code should work fine. But if you are working on localhost or dev server, then you need to set CURLOPT_SSL_VERIFYPEER off as below code:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

Hope it helps you.

Rohit Mittal
  • 2,064
  • 2
  • 8
  • 18