Php file_get_contents not working in Local server

天涯浪子 提交于 2021-01-29 04:40:12

问题


I enabled php in my MAC osX and normal php codes works fine , but I got one strange error today

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

For the above code i get below error on my local server.But above code is working fine on my Hosting.

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

the normal file_get_content(https://yahoo.com); is working fine.Please some one help me


回答1:


The problem is this site you try to call redirects to SSL(https). And then you need the php_openssl.dll module. Otherwise its not working.

Edit your active php.ini find the line:

;extension=php_openssl.dll

and uncomment it.

Edit:

you can make an phpinfo() and look at the top of the output. There you can see which php.inifile is loaded.




回答2:


I had same problem and i finally solved by replace file_get_contents with curl call.

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



回答3:


You have to activate OpenSSL.

;extension=php_openssl.dll

Remove ;

extension=php_openssl.dll

in your php.ini file.




回答4:


There appears to be a problem with your servers SSL certificate, if there is even supposed to be one.

Use $hi = file_get_contents("http://ojooo.com"); instead



来源:https://stackoverflow.com/questions/13589639/php-file-get-contents-not-working-in-local-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!