MAMP PHP cURL and SSL

November 13, 2010 by: VarIncart

I currently develop PHP based websites on a Mac using MAMP. When testing the Interspire Email Marketer API on a local version of a site posting data through to an https:// URL with cURL, I discovered that the version of cURL on MAMP has some issues with certs and SSL.

Original code



My original code posted some XML through to an https URL like so:
$ch = curl_init('https://www.example.com/example-api.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$result = @curl_exec($ch);

The post was failing and all that was being returned into $result was false. Running this line of code after the above:
echo '
', curl_error($ch);
produced this error message:
SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

My solution

I found a forum on the MAMP website which had a whole bunch of instructions about getting updated certificate files and so on, but the simplest solution was to simply not check the cert. I don't need to have it checked because it's a site I trust (being one of my own partner sites).

To disable the SSL checking add this line:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
The revised piece of code in its entirety now looks like this:
$ch = curl_init(IEM_APIURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = @curl_exec($ch);

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
Have you found this script useful? Please support author by PayPal donation.

Comments

One Response to “MAMP PHP cURL and SSL”
  1. Alin says:

    Hmm, I wanna see here, more video tutorial, and please explain me, how to find out in ip from a specific person on the Yahoo Messenger? And by the way this site is wonderful…I m a begginer in web development and I wanna learn more, please keep it like that.

Leave a Reply