通过allow_url_fopen = 0中的服务器配置 [英] Server configuration by allow_url_fopen=0 in
问题描述
运行脚本时出现以下错误.错误消息如下...
I'm getting the following error when running a script. The error message is as follows...
警告:file_get_contents()[function.file-get-contents]:在服务器配置中,第22行/home/satoship/public_html/connect.php中的allow_url_fopen = 0禁用了https://包装器
Warning: file_get_contents() [function.file-get-contents]: https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/satoship/public_html/connect.php on line 22
我知道这是服务器问题,但是为了摆脱上述警告,我需要对服务器做些什么?
I know this is a server issue but what do I need to do to the server in order to get rid of the above warning?
推荐答案
如果您无法修改php.ini文件,请使用cURL: PHP卷曲和Cookies
If you do not have the ability to modify your php.ini file, use cURL: PHP Curl And Cookies
这是我创建的示例函数:
Here is an example function I created:
function get_web_page( $url, $cookiesIn = '' ){
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => true, //return headers in addition to content
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLINFO_HEADER_OUT => true,
CURLOPT_SSL_VERIFYPEER => true, // Validate SSL Cert
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_COOKIE => $cookiesIn
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$rough_content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header_content = substr($rough_content, 0, $header['header_size']);
$body_content = trim(str_replace($header_content, '', $rough_content));
$pattern = "#Set-Cookie:\\s+(?<cookie>[^=]+=[^;]+)#m";
preg_match_all($pattern, $header_content, $matches);
$cookiesOut = implode("; ", $matches['cookie']);
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['headers'] = $header_content;
$header['content'] = $body_content;
$header['cookies'] = $cookiesOut;
return $header;
}
注意:在重新访问此功能时,我注意到我已禁用此代码中的SSL检查.即使在我特定的情况下,我使用它的站点是本地的并且是安全的,但这通常是一个不好的事情.结果,我修改了此代码以默认情况下启用SSL检查.如果出于某些原因需要更改它,则可以只更新CURLOPT_SSL_VERIFYPEER的值,但是如果有人使用此代码,我希望默认情况下该代码是安全的.
NOTE: In revisiting this function I noticed that I had disabled SSL checks in this code. That is generally a BAD thing even though in my particular case the site I was using it on was local and was safe. As a result I've modified this code to have SSL checks on by default. If for some reason you need to change that, you can simply update the value for CURLOPT_SSL_VERIFYPEER, but I wanted the code to be secure by default if someone uses this.
这篇关于通过allow_url_fopen = 0中的服务器配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!