Home  >  Article  >  Backend Development  >  How to solve the problem that file_get_contents cannot request https connection_PHP tutorial

How to solve the problem that file_get_contents cannot request https connection_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:18:00828browse

Error: Warning: fopen() [function.fopen]: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?

There are 3 solutions:

1. For PHP under windows, you only need to delete the ; in front of extension=php_openssl.dll in php.ini and restart the service.

2. For PHP under Linux, you must install the openssl module. After installation, you can access it.

3. If you cannot modify the configuration of the server, then use the curl function to replace the file_get_contents function. Of course, it is not a simple replacement. There are also corresponding parameter configurations to use the curl function normally.

The curl function is encapsulated as follows:

Copy code The code is as follows:

function http_request($url,$timeout=30,$header=array()) {
if (!function_exists('curl_init')) {
throw new Exception('server not install curl');
$ch = curl_init();
curl_setopt($ ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_T IMEOUT, $timeout);
                                                                                                                                 list($header, $ data) = explode("rnrn", $data);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_code == 301 || $http_code == 302) {
$ 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);
$data = curl_exec($ch);
} if ($data = = false) {
               curl_close($ch);                                                     



http://www.bkjia.com/PHPjc/621685.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/621685.html

TechArticle
Error: Warning: fopen() [function.fopen]: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? There are 3 solutions: 1. PHP under windows, just...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn