How can one ensure that a cURL request to an HTTPS site is executed successfully in PHP?
When making a cURL request to an HTTPS site in PHP, it is important to ensure that the SSL certificate verification is enabled. This can be done by setting the CURLOPT_SSL_VERIFYPEER option to true. Additionally, you may need to specify the location of the CA certificate bundle using the CURLOPT_CAINFO option to establish a secure connection.
$url = "https://example.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_CAINFO, '/path/to/cacert.pem');
$response = curl_exec($ch);
if($response === false){
echo 'cURL error: ' . curl_error($ch);
}
curl_close($ch);