在本机调试php程序,服务器需要去访问https的页面,其中函数的封装为
function http_get_contents($url){ if (ini_get("allow_url_fopen") == "1") { $response = file_get_contents($url); }else{ if (!function_exists('curl_init')) { throw new Exception('server not install curl'); } $ch = curl_init(); //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); if (!empty($header)) { curl_setopt($ch, CURLOPT_HTTPHEADER, $header); } $response = curl_exec($ch); list($header, $response) = explode("\r\n\r\n", $response); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code == 301 || $http_code == 302) { //redirect url $matches = array(); preg_match('/Location:(.*?)\n/', $header, $matches); $url = trim(array_pop($matches)); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); $response = curl_exec($ch); } if ($response == false) { curl_close($ch); } @curl_close($ch); } //-------请求为空 if(empty($response)){ //TODO error return ""; } return $response; }
运行后,php页面报这样的问题
file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?
我检查php.ini的配置:
1.里面的extension=php_openssl.dll
是开启的状态,没有被注释。
2.里面的allow_url_fopen = On
表示开启了。
3.如果你是Windows 64bit的操作系统。复制php目录下的php_openssl.dll
到文件夹C:\Windows\SysWOW64
下。如果你是Windows 32bit的操作系统,放到文件夹C:\Windows\System32
。
4.重启apache或者nginx服务器。
打开phpinfo(),有下面的选项
声明:未经允许禁止转载 东东东 陈煜东的博客 文章,谢谢。如经授权,转载请注明: 转载自东东东 陈煜东的博客
近期评论