You’re probably familiar with using PHP cURL to load content from a website via its URL or send a web request (post/get) to consume a particular HTTPS API web service. However, you may have to face with an curl_error: “SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines: SSL3_GET_SERVER_CERTIFICATE: certificate verify failed” – curl_errno: 60
The problem will occur if the SSL certificate on remote site is invalid/expired/un-structed or the cURL is not configured to trust the server’s SSL certificate.
To fix the issue and be able to send request to HTTPS web service, you need to disable cURL verify SSL. Meaning that cURL will accept any SSL certificate. Honestly, this is not a good security practice but it can get your job done.
1. Simple PHP cURL post to HTTPS
The PHP script example below will send a post request to a HTTPS URL and display the return data.
<?php $url = "https://4rapiddev.com/demo/simple_post_https.php"; $post_data = "name=Hoan&message=I'm from 4rapiddev.com"; $response = post_https($url, $post_data); echo $response; function post_https($url, $post_data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL , $url ); curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1); curl_setopt($ch, CURLOPT_TIMEOUT , 60); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_USERAGENT , "" ); curl_setopt($ch, CURLOPT_POST , 1); curl_setopt($ch, CURLOPT_POSTFIELDS , $post_data ); $xml_response = curl_exec($ch); if (curl_errno($ch)) { $error_message = curl_error($ch); $error_no = curl_errno($ch); echo "error_message: " . $error_message . "<br>"; echo "error_no: " . $error_no . "<br>"; } curl_close($ch); return $xml_response; } ?> |
2. Output:
Hello Hoan, you submitted a message: I'm from 4rapiddev.com<br> |