PHP calls Curl Prompt error: SSL certificate problem, verify that CA cert is OK. Details:error:14090086:ssl routines:ssl3_get_server_certificate:certificate verify failed. This is due to a certificate expiration.
Ssl-error
You need to download the trust certificate to HTTP://CURL.HAXX.SE/CA/CACERT.PEM. After downloading, there are two ways to make it effective:
The first method: Modify the PHP.ini, find the [Curl] node, and if not, add it at the bottom of the php.ini.
[Curl]
; Modify the path saved for HTTP://CURL.HAXX.SE/CA/CACERT.PEM
curl.cainfo= "D:/php/cacert.pem"
The second method: Save to the directory where the program is located, add a sentence when calling Curl:
<?php
#cacert. Pem to Http://curl.haxx.se/ca/cacert.pem download
curl_setopt ($curl, Curlopt_cainfo, DirName (__file__). '/cacert.pem ');
?>
You can use the following code to automatically identify HTTPS or HTTP
function Curlpost ($url, $data, $timeout = 30)
{
$ssl = substr ($url, 0, 8) = = "https://"? True:false;
$ch = Curl_init ();
$opt = Array (
Curlopt_url => $url,
Curlopt_post => 1,
Curlopt_header => 0,
Curlopt_postfields => (array) $data,
Curlopt_returntransfer => 1,
Curlopt_timeout => $timeout,
);
if ($SSL)
{
$opt [Curlopt_ssl_verifyhost] = 1;
$opt [Curlopt_ssl_verifypeer] = FALSE;
}
Curl_setopt_array ($ch, $opt);
$data = curl_exec ($ch);
Curl_close ($ch);
return $data;
}
$data = Curlpost (' https://www.111cn.net ', Array (' P ' => ' Hello '));
Echo ($data);