PHP Curl Access calls HTTPS times wrong solution

Source: Internet
Author: User


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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.