简体   繁体   English

PHP CURL HTTPS问题

[英]PHP CURL HTTPS Issue

I am having big problems with accessing lots of https sites to download pages and especially files. 我在访问许多https网站来下载页面(尤其是文件)时遇到了大问题。

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. 我也曾尝试下载SSL证书,但这无济于事。 I have also upgraded my curl lib to the very latest as I understand that could cause issues. 我也将curl lib升级到最新版本,因为我了解这可能会导致问题。

I am using PHP5, and it is not an option for me to upgrade above that. 我正在使用PHP5,但我不能选择在上面升级。

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 MTIA亚历克西斯

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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