4

Im trying to convert a curl-statement with an authentication header to a php curl request. But it doesn't seem to be working, because I receive the error below with echo 'error:' . curl_error($ch);:

error:SSL certificate problem: unable to get local issuer certificate

My curl-command looks like this:

curl --user XXXX:YYYY "URL"

My php-curl looks like this:

$login = 'XXXX';
$password = 'YYYY';
$url = 'URL';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
echo curl_exec($ch);
$result = curl_exec($ch);

if ($result != false){
        echo "SUCCESS";
}else{
        echo "<br>";
        echo 'error:' . curl_error($ch);
        echo "<br>";
    }
curl_close($ch);  
echo($result);

Does anyone sees my fault?

fsulser
  • 853
  • 2
  • 10
  • 34

1 Answers1

3

cURL is not able to verify the authenticity of the certificate being used, because the certificate for the signing authority cannot be found in the local database.

This might be symptomatic of a self signed certificate being used.

What you should do is add the certificate for the signing authority to /etc/ssl/certs/ca-certificates.crt.

What you can do is use curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);, which will disable the check that is failing.

You really should use the first option.

Joe Watkins
  • 17,032
  • 5
  • 41
  • 62