How can SSL verification be properly handled when using cURL in PHP scripts?

When using cURL in PHP scripts, SSL verification can be properly handled by setting the CURLOPT_SSL_VERIFYPEER option to true and the CURLOPT_CAINFO option to the path of a certificate authority file. This ensures that cURL verifies the SSL certificate of the server it is connecting to, providing secure communication.

<?php
$url = 'https://example.com/api';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_CAINFO, '/path/to/certificate.pem');
$response = curl_exec($ch);
if($response === false){
    echo 'cURL error: ' . curl_error($ch);
}
curl_close($ch);
echo $response;
?>