ds2321 2018-07-07 21:52
浏览 58

PHP CURL HTTPS问题

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

  • 写回答

1条回答 默认 最新

  • dpa31905 2018-07-07 22:06
    关注

    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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测