File_get_contents cannot request a workaround for HTTPS connections
Method 1:
PHP.ini The default configuration, the link to the HTTPS is read with file_get_contents, the error is as follows:
Warning:fopen () [function.fopen]: Unable to find the wrapper "https"-do you forget to enable it when you configured PH P?
The solution has 3:
1.windows PHP, only need to php.ini in front of the Extension=php_openssl.dll , delete, restart the service can be.
2.linux PHP, you must install the OpenSSL module, installed in the future can be accessed.
3. If the server you can not modify the configuration, then use the Curl function to replace the file_get_contents function, of course, is not a simple replacement ah. There is also a corresponding parameter configuration to use the Curl function properly.
The Curl function is encapsulated as follows:
[PHP]View Plaincopyprint?
- 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 ("\r\n\r\n", $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;
- }
php to turn on Curl
To open the PHP Curl Library
1). Remove the Windows/php.ini file; Extension=php_curl.dll Front; /* with Echo phpinfo (); View PHP.ini's Path */
2). Copy the Php5/libeay32.dll,ssleay32.dll to the system directory windows/
3). Restart Apache
Configure PHP to support curl
Curl is a file transfer tool that works with URL syntax in the command line mode. It supports many protocols: FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE, and LDAP. Curl also supports HTTPS authentication, HTTP POST method, HTTP put method, FTP upload, Kerberos authentication, HTTP upload, proxy server, cookies, username/password Authentication, download file breakpoint continuation, upload file breakpoint continuation, HTTP Proxy service (proxy tunneling), even it supports IPV6, SOCKS5 proxy server, uploading files via HTTP proxy server to FTP server and so on, the function is very powerful. Windows operating system under the network ant, the Internet Express (FlashGet) function it can do. To be exact, curl supports file uploads and downloads, so it's a comprehensive transfer tool, but traditionally, users are accustomed to calling curl a download tool.
Configuration method:
1, copy the PHP directory of Libeay32.dll and ssleay32.dll two files to system32 directory.
2, modify PHP.ini: Configure the Extension_dir, remove extension = Php_curl.dll front of the semicolon.
---------------------------
Installation of extended Php_curl.dll under PHP
---------------------------
The Php_curl.dll is already built in, and in the EXT directory, this DLL is used to support SSL and zlib.
Find the Extension=php_curl.dll in php.ini and remove the previous comment.
Set Extension_dir=c:phpext, refresh php page times wrong, said to find module Php_curl.dll.
Copy Php_curl.dll to Windowssystem32, or the same mistake.
On the internet to find a bit, you need to:
Libeay32.dll, Ssleay32.dll, Php5ts.dll, Php_curl.dll
are copied to the System32 directory, restart IIS.
File_get_contents Unable to request a workaround for HTTPS connections PHP turns on Curl