首页 > 开发 > PHP > 正文

file_get_contents()获取https出现这个错误Unable to find the wrapper “ht

2024-05-04 22:01:24
字体:
来源:转载
供稿:网友

file_get_contents()获取https出现这个错误Unable to find the wrapper “https” – did

解决办法一,如果你是用的服务器,可以参考这个办法,修改php配置文件(win主机),来支持https

在php.ini中找到并修改:

extension=php_openssl.dll

allow_url_include = On

重启服务就可以了,如果你的是linux服务器,linux下的PHP,就必须安装openssl模块,安装好了以后就可以访了。

解决办法二,如果你用的不是服务器,你用的主机,你没法更改php的配置,你可以通过使用curl函数来替代file_get_contents函数,当然你的主机必须支持curl函数。

  1. <?php 
  2. function getSslPage($url) { 
  3. $ch = curl_init(); 
  4. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
  5. curl_setopt($ch, CURLOPT_HEADER, false); 
  6. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
  7. curl_setopt($ch, CURLOPT_URL, $url); 
  8. curl_setopt($ch, CURLOPT_REFERER, $url); 
  9. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
  10. $result = curl_exec($ch); 
  11. curl_close($ch); 
  12. return $result
  13. echo getSslPage($_GET['url']); 
  14. ?> 

检查主机是否支持php的file_get_contents函数,讲一下代码存储为php文件,在空间运行,即可得出结果。

  1. <?php 
  2. echo ‘Curl: ‘, function_exists(‘curl_version’) ? ‘Enabled’ : ‘Disabled’ . ‘<br /> 
  3. file_get_contents: ‘, file_get_contents(__FILE__) ? ‘Enabled’ : ‘Disabled’; 
  4. ?> 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表