What is the role of cURL in making SSL requests to a PHP script?

To make SSL requests to a PHP script using cURL, you need to ensure that cURL is properly configured to handle SSL connections. This involves setting the appropriate cURL options such as CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST to verify the SSL certificate of the server. Additionally, you may need to specify the path to the CA certificate bundle to validate the SSL certificate.

$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_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, '/path/to/ca-bundle.crt');

$response = curl_exec($ch);

if($response === false){
    echo 'cURL error: ' . curl_error($ch);
}

curl_close($ch);

// Process the response