2011-03-26 45 views
111

問題在於這個問題。我已經對這方面的解決方案進行了徹底的調查,我知道這有些話題,我也跟着他們,沒有任何工作。話雖如此,我將列出我到目前爲止所做的一切。我使用Zend Debugging在我的Windows XP計算機上的最新Eclipse版本上運行PHP 5.2.14。我有1 GB的RAM。我有安裝Apache,MySQL和FileZilla的XAMPP。 從XAMPP控制面板中點擊了管理就去https:// localhost/xampp/無法找到包裝器「https」 - 您配置PHP時是否忘記啓用它?

在XAMPP下面我做(Apache的這些變化過程中關閉)。從那裏,我接受了歡迎頁面上來自該行的證書:

For OpenSSL support please use the test certificate with https:// 127.0.0.1 or https:// localhost.

在同一節中,我檢查phpinfo()。在'環境'下,SERVER["HTTPS"]on。在「Apache環境」下,HTTPSOn。 'PHP變量下,_SERVER["HTTPS"]On。在'Phar'下,OpenSSL supportdisabled(安裝ext/openssl)。我不知道如何啓用Phar。

現在關於C:\ xampp中的文件本身,我去了PHP文件夾。在生產和開發php.ini文件(比對不起更安全)下,我有allow_url_fopen=On,allow_url_include=On,並且我刪除了分號,以便extension=php_openssl.dll不再被註釋掉。我甚至確認.dll位於PHP文件夾的ext文件夾中。 libeay32.dll和ssleay32.dll都在PHP和Apache文件夾中。 Apache文件夾不包含生產性或開發性php.ini文件。

我去了http://www.slproweb.com/products/Win32OpenSSL.html並安裝了Win32 OpenSSL v1.0.0d以保證安全。

現在的代碼有問題,我retrieve_website.php行看起來是這樣的:

$urlquery = "https://www.googleapis.com/customsearch/v1?key=".$appid."&cx=".$google_searchid."&q=".$query."&alt=atom&num=".$results; 
$xmlresults = file_get_contents($urlquery); 

我還有其他兩個網站,我查詢,但他們都通過HTTP服務,他們工作得很好。我也有這行代碼附​​近腳本的末尾輸入:

echo 'openssl: ', extension_loaded ('openssl') ? 'yes':'no', "\n"; 
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n"; 
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n"; 
echo 'wrappers: ', var_dump($w); 

當我運行它作爲一個PHP腳本在Eclipse上,一切都輸出完全沒有我與這些結果一起想要的方式:

openssl: yes 
http wrapper: yes 
https wrapper: yes 
wrappers: array(10) { 
    [0]=> 
    string(5) "https" 
    [1]=> 
    string(4) "ftps" 
    [2]=> 
    string(3) "php" 
    [3]=> 
    string(4) "file" 
    [4]=> 
    string(4) "data" 
    [5]=> 
    string(4) "http" 
    [6]=> 
    string(3) "ftp" 
    [7]=> 
    string(13) "compress.zlib" 
    [8]=> 
    string(14) "compress.bzip2" 
    [9]=> 
    string(3) "zip" 
} 

儘管所有這些變化我做了(後,我開始了Apache的),我仍然得到同樣的錯誤,我第一次通過http://localhost/tutorial/retrieve_website.php訪問Eclipse和Firefox中的PHP腳本:

Warning: file_get_contents() [function.file-get-contents]: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in C:\xampp\htdocs\tutorial\retrieve_website.php on line 29

Warning: file_get_contents(https:// www.googleapis.com/customsearch/v1?key=removed API ID&cx=removed search ID&q=The+Devil+went+down+to+Georgia&alt=atom&num=5) [function.file-get-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\tutorial\retrieve_website.php on line 29

Warning: DOMDocument::loadXML() [domdocument.loadxml]: Empty string supplied as input in C:\xampp\htdocs\tutorial\retrieve_website.php on line 33

openssl: no http wrapper: yes https wrapper: no wrappers: array(10) { [0]=> string(3) "php" [1]=> string(4) "file" [2]=> string(4) "glob" [3]=> string(4) "data" [4]=> string(4) "http" [5]=> string(3) "ftp" [6]=> string(3) "zip" [7]=> string(13) "compress.zlib" [8]=> string(14) "compress.bzip2" [9]=> string(4) "phar" }

什麼是我忽視或未能做到的?據我自己的知識,我已經完成了我所研究的關於HTTPS和OpenSSL的所有內容。

回答

16

您的Apache可能未編譯時使用SSL支持。無論如何,請使用cURL而不是file_get_contents。試試這個代碼,如果失敗了,那麼我是對的。

function curl_get_contents($url) 
{ 
    $curl = curl_init($url); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); 
    $data = curl_exec($curl); 
    curl_close($curl); 
    return $data; 
} 
+1

跑了捲曲功能,你給我和更換'$ xmlresults =的file_get_contents($ urlquery);'和'$ xmlresults =捲曲($ urlquery);'。 PHP腳本運行得很好,其結果與file_get_contents()相同。通過http://localhost/tutorial/retrieve_website.php將其作爲PHP Web頁面運行,並且出現此錯誤:致命錯誤:調用C:\ xampp \ htdocs \ tutorial \ retrieve_website.php中的未定義函數curl_init() 14' – 2011-03-26 20:04:53

+1

問題是在SSL支持probaby,運行** phpinfo()**並檢查是否有以下命令/標誌:''--with-openssl =/usr''--with-openssl-dir =/usr '',基本上你需要使用SSL支持來編譯Apache,你也應該啓用比FGC快幾倍的cURL,並且有很多選項。我不知道如何在Windows上執行此操作,很抱歉。 – 2011-03-26 20:13:58

+1

唯一接近的就是在phpinfo()的頂部配置命令,並且沒有包含--with-openssl相關的任何東西。它包含其他 - 與事物。小更新:在本地主機上,檢查狀態,它說HTTPS(SSL)已激活。 – 2011-03-26 21:52:24

2

整天周圍窺探後,我想出答案感謝這個指南: http://piwigo.org/forum/viewtopic.php?id=15727

基本上根據日食 - >窗口 - >首選項 - > PHP可執行文件,還有一個部分,其中的.exe和.ini被引用。當您在幫助菜單中安裝Eclipse日誌安裝新軟件中的PHP開發工具SDK功能時,默認的部分位於Eclipse目錄中。

因此,我添加了一個名爲PHP 5.3.5(CGI)的新可執行文件,並引用了xampp的php文件夾中的cgi.exe和.ini。

謝謝webarto給你的時間來幫助我。

2

試試這個:

function curl($url){ 
    $curl = curl_init($url); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); 
    **$buffer = curl_exec($curl);** 
    curl_close($curl); 
    **return $buffer;** 
} 
+1

這與這個問題已經有了什麼不同[這個答案](http://stackoverflow.com/a/5444496/3000068)*? – HPierce 2016-10-29 22:40:47

156

/apache/bin/php.ini解決它在XAMPP通過取消註釋;extension=php_openssl.dll儘管 phpinfo()函數告訴我/php/php.ini是加載ini文件。

編輯:我猜Ezra答案是最好的解決方案,直接將擴展行添加到適當的ini文件。

+1

你確定它的'/ apache/bin/php.ini',我在XAMPP Portable Light 1.8.1中找不到它嗎?然而'php/php.ini'存在,但是在這裏啓用ssl並沒有幫助:( – 2012-11-12 17:18:30

+5

在wamp上,我只取消了openssl的註釋並且它工作:) – 2013-01-31 09:27:46

+1

這個答案會產生另一個問題,因爲openssl現在被禁用並且會拋出一個錯誤如果我get_file_contents一個安全的鏈接 – thedjaney 2013-07-26 05:37:06

87

我必須將extension=php_openssl.dll添加到位於xampp/php/php.ini的我的php.ini文件中。不知何故,它不在那裏,添加它並重新啓動Apache後,一切正常。

+1

也有同樣的問題。這工作。 – phirschybar 2012-04-07 04:11:20

+1

這對我有用!謝謝 – 2012-08-01 22:48:04

+1

我不得不添加該行,因爲它不在php.ini中 - 但後來做了這個訣竅 - 謝謝! – 2012-09-11 09:24:00

28

只需在php.ini文件中添加兩行即可。

extension=php_openssl.dll 
allow_url_include = On 

它爲我工作。

+7

我正在使用wamp,而您需要在apache文件夾中編輯php.ini,而不是PHP文件夾中的常用文件:O – 2013-06-03 15:27:17

6

在我的情況下,問題是由於WAMP使用與Apache不同的php.ini for CLI,所以通過WAMP菜單進行的設置不適用於CLI。只需修改CLI php.ini,它就可以工作。

+1

Wel您是怎麼做到的?我在哪裏可以找到CLI php。ini – botenvouwer 2013-01-30 16:38:06

+1

Mine is located:'C:\ path \ to \ wamp \ bin \ php \ php5.3.10 \ php.ini' – dtbarne 2013-01-30 21:52:57

+2

感謝您的回答,我以爲那裏有多個php.ini文件。當我搜索時,我只找到一個,我取消註釋:; extension = php_openssl.dll但是我使用xammp,我把它與wamp混淆了。現在它起作用了,是的! – botenvouwer 2013-01-31 09:23:54

4

您可以改用此功能。

function get_url_contents($url){ 
    if (function_exists('file_get_contents')) { 
    $result = @file_get_contents($url); 
    } 
    if ($result == '') { 
    $ch = curl_init(); 
    $timeout = 30; 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
    $result = curl_exec($ch); 
    curl_close($ch); 
    } 

    return $result; 
} 
5
在了OpenSuse 12.1唯一

需要的是:

zypper in php5-openssl 
+1

你能解釋一下嗎? – 2014-02-12 06:03:01

+1

我的意思是我收到錯誤消息「無法找到包裝器」https「 - 您忘記在配置PHP時啓用它嗎?」並通過在命令行中輸入「zypper in php5-openssl」來解決它。這解決了錯誤。 – TheSatinKnight 2014-10-09 04:26:38

11

我能在OpenSSL的推廣與它爲我工作:)

;延長= php_openssl.dll

extension = php_openssl.dll

+2

爲我工作:) – Rahul 2014-05-02 09:59:20

1

我也有這個錯誤。我發現我的PHP版本沒有編譯openssl,所以只需將擴展指令添加到php.ini中是不夠的。我不知道你怎麼會有你的具體情況來解決這個問題,但對我來說,我使用的MacPorts,命令只是:

sudo port install php5-openssl 
4

對於我來說,我不得不取消註釋PHP這些行。ini:

extension=php_openssl.dll 
extension_dir = "ext" 

如果php_openssl.dll位於「ext」文件夾中,則可以使用「ext」。

注意:我不得不這樣做兩個我的php.ini文件,否則它將無法正常工作。一個設在VS.PHP安裝文件夾,和其他上的PHP文件夾

C:\Program Files (x86)\Jcx.Software\VS.Php\2013\Php 5.6 
C:\Program Files (x86)\PHP\v5.6 

Source

1

我使用opsenSUSE的飛躍,我有同樣的問題 - 這意味着沒有支持適用於OpenSSL。這是我解決它的方式:

  1. 打開YaST。
  2. 轉到軟件管理。
  3. 在左側窗格的搜索框中,輸入「php5-openssl」並按回車鍵。
  4. 單擊右側窗格中'php5-openssl'旁邊的複選框將其選中,然後單擊'接受'(這增加了對OpenSSL的支持)。
  5. 重啓Apache:sudo service apache2 restart

就是這樣,你就大功告成了。

3

在MAC AMPPS上,我用下面的方法更新了php-5.5.ini,現在它可以工作。

allow_url_include = On 
extension=openssl.so 
相關問題