简体   繁体   中英

PHP CURL HTTPS Issue

I am having big problems with accessing lots of https sites to download pages and especially files.

I have done multiple searches on the interweb over this problem and the bulk of them say the same thing:

use the following:

curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);

But this never seems to work for me.

I have also tried downloading the SSL certificate but that does not help either. I have also upgraded my curl lib to the very latest as I understand that could cause issues.

I am using PHP5, and it is not an option for me to upgrade above that.

Here is an example of my code and one of the urls I am trying to access:

<?php
$file_source="https://www.faa.gov/"
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $file_source);
curl_setopt($ch, CURLOPT_REFERER,  $file_source);
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
$data = curl_exec ($ch);
$error = curl_error($ch); 
curl_close ($ch);
?>

Can anyone please help as I am tearing my hair out over this.

MTIA Alexis

This is working fine for me:

$fullurl="https://www.faa.gov/";

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);

curl_setopt($ch, CURLOPT_URL, $fullurl);

$returned = curl_exec($ch);
var_dump($returned);
curl_close ($ch);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM