Error using php Curl ssl certificate

Asked

Viewed 1,716 times

1

I’m trying to use Curl. The problem is that in some pages it works normally, in others I have as output the following error:

SSL certificate problem: unable to get local issuer certificate

Here is my code:

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.youtube.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
?>

I am beginner in php and also do not understand much about this Curl tool, but what would be the solution to this error?

I am using Xampp.

1 answer

0

Your problem is due to the lack of some parameters required when making requests to https page. The correct one would be:

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.youtube.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$output = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
?>

I have a class to handle Curl, can see you at this link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.