How can SSL certificate verification issues be resolved when using cURL for HTTPS requests in PHP?
When using cURL for HTTPS requests in PHP, SSL certificate verification issues can be resolved by setting the CURLOPT_SSL_VERIFYPEER option to false. This will disable the verification of the SSL certificate, which may be necessary in some cases when dealing with self-signed certificates or other certificate-related problems.
<?php
$url = 'https://example.com/api';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL verification
$response = curl_exec($ch);
if($response === false){
echo 'cURL error: ' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);
?>