2011-03-26 44 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 
相关问题