2012-11-27 12 views
1

我能在我的MAC OSX PHP和正常的PHP代碼工作正常的工作,但我今天的PHP的file_get_contents不是本地服務器

<?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);工作fine.Please有人幫我

回答

1

問題是您嘗試將此網站調用重定向到SSL(https)。然後你需要php_openssl.dll模塊。否則它不工作。

編輯您的積極php.ini找到行:

;extension=php_openssl.dll

,並取消它。

編輯:

你可以讓一個phpinfo(),並期待在輸出的頂部。在那裏你可以看到哪個文件被加載。

+1

是的,我打開了php.ini文件!但是你知道在終端中找到文本的快捷方式? –

+0

嘿,現在我只得到空白文件 –

-1

似乎有與您的服務器SSL證書有問題,如果有,甚至應該是一個。

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

+0

是啊,我變了,但還是同樣的錯誤。但是相同的代碼工作正常,在託管...但不是我的本地服務器上 –

+0

它不工作,因爲該網站重定向到HTTPS。 – Stony

+0

是啊,但工作正常我的主機 –

0

你必須激活OpenSSL的。

;extension=php_openssl.dll 

刪除;

extension=php_openssl.dll 

在您的php.ini文件中。

+0

我應該在哪裏編輯它? –

+0

搜索你的php.ini文件。在你的控制檯運行php --ini –

+0

是的,我打開了php.ini文件!但是你知道在終端中找到文本的快捷方式? –

1

我有同樣的問題,我終於解決了,用file_get_contents代替curl調用。

$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); 
相關問題