Allan Vest

Expert Web Development

PHP & Curl on Windows

leave a comment

Today I was testing an application that is known to work under Linux and Apache to see if it functioned the same under Windows and Apache.

Turns out, the following code fetches a HTTPS pageĀ  just find under Linux and Apache, but returns nothing under Windows and Apache.

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $post_url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
$result_array = curl_exec ($ch);

Adding the following extra settings lets the code work on both Linux and Windows and seems to work regardless of whether the page being fetched is HTTP or HTTPS.

curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

Written by allan

March 3rd, 2011 at 7:08 pm

Posted in Web Development