How to use CURL with PHP to get content from SSL-enabled sites
Posted by zz-James Moir on 21 June 2016 04:08 PM
You wish to use CURL to get information from secure https:// sites but get validation errors.
The CURL libraries no longer include a list of certificates to validate against.
As such, these need to be obtained and then referenced in your code.
An example is given below.
Obtain CA Certificate bundle in PEM format from http://curl.haxx.se/ca/cacert.pem and save this to a location within the httpdocs directory structure.
Within your code reference this.
An example :
// Set the URL to visit
// In this example we are referring to a page that handles xml
// Initialise Curl
// Configure curl for website
// Set up to view correct page type
curl_setopt($curl, CURLOPT_CAPATH, "/usr/local/www/vhosts/<yourdomainname>/httpdocs/cacert.pem");
// Tell the curl instance to talk to the server using HTTP POST
$result = curl_exec($curl);