Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Using cURL to access HTTPS (SSL) protected sites

Tags:

php

curl

https

ssl

The following code returns Exit code 58.

From cURL documentation: CURLE_SSL_CERTPROBLEM (58) problem with the local client certificate.

// create a new CURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_HEADER, false);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

curl_setopt($ch, CURLOPT_SSLCERT, getcwd() . $CERT);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD,"XXXXX");

curl_setopt($ch, CURLOPT_SSLVERSION, 3);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content Type: text/xml',
    'User-Agent: XXXXX',
    'User-Name: XXXXX'
));

$RESPONSE = curl_exec($ch);  

var_dump($RESPONSE);

// close CURL resource, and free up system resources
curl_close($ch);

Is there something I'm missing?

like image 916
Ren Avatar asked Jun 30 '26 02:06

Ren


1 Answers

Make sure the file in getcwd() . $CERT exists and is a valid PEM certificate. If it seems ok, set the following option to get more SSL certification details output to STDERR:

curl_setopt($ch, CURLOPT_CERTINFO, true);

Note that this setting only has effect if CURLOPT_VERBOSE is set to true, which you already have.

like image 112
Kaivosukeltaja Avatar answered Jul 02 '26 18:07

Kaivosukeltaja



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!