File_get_contents cannot request a solution for https connection. Using file_get_contents to fail to request https connection issue. The prepare method is very simple. you only need to enable php_openssl. of course, you need to install the openssl module in linux. By default, PHP. ini is configured with file_get_contents, which cannot be used to request https connections. the restore method is very simple. you only need to enable php_openssl. of course, you need to install the openssl module in linux.
In the default configuration of PHP. ini, the following error occurs when file_get_contents is used to read the https link:
Warning: fopen () [function. fopen]: Unable to find the wrapper "https"-did you forget to enable it when you configured PHP?
Solution 3:
1. for PHP in windows, you only needIn php. ini, set extension = php_openssl.dllDelete the previous one. restart the service.
2. for PHP in linux, you must install the openssl module. after installation, you can access it.
Installation method
OpenSSL library installation
Official website: http://www.openssl.org
Download Page: http://www.openssl.org/source/
Download the latest version
Http://www.openssl.org/source/openssl-1.0.0a.tar.gz
Decompress:
Tar-zxvf openssl-1.0.0d.tar.gz, unzipped Directory: openssl-1.0.0d
Then enter the cd openssl-1.0.0d for configuration, compilation, installation
Configuration
./Configure or./config
Compile
Make
Install
Make install
3. if you cannot modify the configuration on the server, use the curl function to replace the file_get_contents function. of course it is not a simple replacement. The curl function can be used properly only with corresponding parameter configurations.
The curl function is encapsulated as follows:
| 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_TIMEOUT, $ timeout ); If (! Empty ($ header )){ Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header ); } $ Data = curl_exec ($ ch ); 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 ); } @ Curl_close ($ ch ); Return $ data; } |
Bytes. PHP. ini default configuration...