CURL PHP – error:SSL certificate problem: self signed certificate in certificate chain

http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

So after downloading this cacert.pem file into your project, in PHP you can now do this:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_CAINFO, "/path/to/cacert.pem");

Alternatively, this can be set globally by adding the following to your php.ini

curl.cainfo=/path/to/cacert.pem
echo getcwd();

function _isCurl(){
    return function_exists('curl_version');
}

if( _isCurl()){echo 'cURL is enabled';} else{echo 'cURL is disabled';}

echo '
'; echo '
';

$nameEvent = 'Forum2017';
$user = "wpuser";
$password = "aDkhm49k";
$url = "https://sapeventsadc41c363.hana.ondemand.com/eventdb/services/EventDBService.xsodata";
$headers = array('Content-Type: application/json', 'charset: utf-8', 'accept:application/json');
$curlError = "We can't complete your request now.";

$table = 'Event';
$column = 'SAPCRM_id';
$value = $nameEvent;


$ch = curl_init($url.'/'.$table.'?%24filter='.$column.'%20eq%20\''.$value.'\'');
curl_exec($ch);
if (!curl_errno($ch)) {

    //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
    // curl_setopt($ch, CURLOPT_CAINFO, "cacert.pem");
    // curl_setopt($curl, CURLOPT_VERBOSE, 1); 

    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_NOBODY, false);
    curl_setopt($ch,CURLOPT_USERPWD,$user.":".$password);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    

    echo $datos = curl_exec($ch);
} else {
    echo $curlError;
}

echo "
"; echo "
"; if(curl_error($ch)) { echo 'error:' . curl_error($ch); } curl_close($ch); echo '

';

Solo en servidores WINDOWS

Stop turning off CURLOPT_SSL_VERIFYPEER and fix your PHP config



Tu opinión es importante para mi, ¿Te ha resultado útil este artículo?

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

*