PHP cURL with HTTPS
When using PHP cURL against a SSL powered website, you need to add this line (the red one) before calling curl_exec:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://my.domain.com');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'mycookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'mycookie.txt');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$buffer = curl_exec($ch);
(Notes that this is just a workaround, for proper fix please read this article: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://my.domain.com');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'mycookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'mycookie.txt');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$buffer = curl_exec($ch);
(Notes that this is just a workaround, for proper fix please read this article: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/)
Comments
Post a Comment