0

I have now tried a lot of different solutions but non of those curl settings has ever worked... I just want to get the sourcecode of the webpage back...

And yeah, I know there is file_get_contents(). But I need and want to use curl instand of file_get_contents(). Where is the error? How can I get the content of the webpage with curl?

$url = "https://google.de";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($curl, CURLOPT_HTTPHEADER, array(
//    "API-Token: " . APITOKEN . "",
//    "API-Secret: " . APISECRET . "",
//));

$response = curl_exec($curl);
echo "This is the response...:\n" . $response;

$response is always empty... Even if I save the variable to a text file... Here the picture which proves it!

Picture

Greetings and Thank You!

2 Answers2

0

Please dump curl_error($curl). Then you will get "SSL certificate problem: unable to get local issuer certificate".

You can simply set the following options to avoid this error:

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

Warn: the above solution disables SSL verification and is not secure. A secure solution is to set the certification of cURL:

curl_setopt ($curl, CURLOPT_CAINFO, "PATH_TO/cacert.pem");
Clarence
  • 721
  • 1
  • 5
  • 9
0
            If you will check error  then you will show below error

        if(!curl_exec($curl)){
          die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
           }

 Error: "SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed" - Code: 60

    To solve this issue you can follow this link-

    https://wehavefaces.net/fixing-ssl-certificate-problem-when-performing-https-requests-in-php-e3b2bb5c58f6
harsh kumar
  • 165
  • 7