php使用file_get_contents()时出现错误Unable to find the wrapper “https” – did

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函数。

<?php

function getSslPage($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
echo getSslPage($_GET['url']);
?>

猜你喜欢

转载自hnlixf.iteye.com/blog/2359301