繁体   English   中英

PHP file_get_contents在本地服务器中不起作用

[英]Php file_get_contents not working in Local server

我在MAC osX中启用了php,正常的php代码可以正常工作,但今天却遇到一个奇怪的错误

<?php 
$hi = file_get_contents("https://ojooo.com");
echo $hi;
?>

对于上面的代码,我在本地服务器上收到以下错误。但是上面的代码在我的主机上工作正常。

Warning: file_get_contents() [function.file-get-contents]: SSL operation failed with code 1. OpenSSL Error messages: error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:reason(1112) in /Library/WebServer/Documents/hi/index.php on line 2

Warning: file_get_contents() [function.file-get-contents]: Failed to enable crypto in /Library/WebServer/Documents/hi/index.php on line 2

Warning: file_get_contents(https://ojooo.com) [function.file-get-contents]: failed to open stream: operation failed in /Library/WebServer/Documents/hi/index.php on line 2

正常的file_get_content(https://yahoo.com); 工作正常。请有人帮我

问题是您尝试调用此站点重定向到SSL(https)。 然后,您需要php_openssl.dll模块。 否则它不起作用。

编辑您的活动php.ini找到以下行:

;extension=php_openssl.dll

并取消注释。

编辑:

您可以制作一个phpinfo()并查看输出的顶部。 在那里,您可以看到哪个php.ini文件已加载。

我有同样的问题,最后我通过用curl调用替换file_get_contents来解决。

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
$content = curl_exec($curl);
curl_close($curl);

您必须激活OpenSSL。

;extension=php_openssl.dll

去掉 ;

extension=php_openssl.dll

在您的php.ini文件中。

您的服务器SSL证书似乎存在问题,甚至应该是SSL证书。

使用$hi = file_get_contents("http://ojooo.com"); 代替

暂无
暂无

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

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