【问题标题】:Cant open a https website with php and fopen无法使用 php 和 fopen 打开 https 网站
【发布时间】:2010-01-11 06:17:14
【问题描述】:

我正在使用 fopen 来检索 URL 的内容。 它适用于 http URL,但不适用于 https URL

谁能明白为什么??

<?php

//this works fine
echo ("<br><br>url 1 is ".OutputURL("http://nuenergy.acornsoftware.com.au/staff/interface/index.php"));

//returns nothing
echo ("<br><br>url 2 is ".OutputURL("https://nuenergy.acornsoftware.com.au/staff/interface/index.php"));

function OutputURL($url)
{
  $handle = fopen($url, "r");
  $contents = stream_get_contents($handle);
  fclose($handle);
  return $contents;
}
//
?>

【问题讨论】:

标签: php https fopen


【解决方案1】:

您需要使用 PHP 安装和配置 OpenSSL,我建议您在 ServerFault 上提问。

另外,您可以只使用file_get_contents() 而不是OutputURL()

【讨论】:

    【解决方案2】:

    问题不在于 PHP 没有为 HTTPS 返回任何内容,而是您的文件没有为文件的 HTTPS 版本输出任何内容。当我查看 HTTP 版本时,它会输出一个小的 XML 图,表示某种“未找到文件”错误。当我查看文件的 HTTPS 形式时,它返回一个空白页面,源代码中绝对没有内容。您需要查看您的 Apache 配置并确保它正确指向所有文件。

    【讨论】:

      【解决方案3】:

      可能是您的 apache/php 设置不支持通过 fopen 的 https,或者您的服务器的防火墙阻止了这种类型的连接。

      【讨论】:

        猜你喜欢
        • 2015-01-04
        • 1970-01-01
        • 2016-05-06
        • 2016-01-13
        • 2016-10-06
        • 1970-01-01
        • 2010-12-17
        • 1970-01-01
        相关资源
        最近更新 更多