无法使用php和fopen打开https网站

时间:2010-01-11 06:17:14

标签: php https fopen

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

谁能明白为什么?

<?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;
}
//
?>

3 个答案:

答案 0 :(得分:5)

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

此外,您可以使用file_get_contents()代替OutputURL()

答案 1 :(得分:2)

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

答案 2 :(得分:0)

要么你的apache / php设置不支持通过fopen的https,要么你的服务器的防火墙阻止了这种类型的连接。