php 服务器配置通过allow_url_fopen=0 in
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21677579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Server configuration by allow_url_fopen=0 in
提问by JohnThomas
I'm getting the following error when running a script. The error message is as follows...
运行脚本时出现以下错误。错误信息如下...
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
警告:file_get_contents() [function.file-get-contents]:https:// 包装器在服务器配置中被 /home/satoship/public_html/connect.php 第 22 行中的 allow_url_fopen=0 禁用
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?
我知道这是服务器问题,但我需要对服务器做什么才能消除上述警告?
回答by cMinor
@blytung Has a nice function to replace that function
@blytung 有一个很好的功能来替换该功能
<?php
$url = "http://www.example.org/";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
echo "\n<br />";
$contents = '';
} else {
curl_close($ch);
}
if (!is_string($contents) || !strlen($contents)) {
echo "Failed to get contents.";
$contents = '';
}
echo $contents;
?>
回答by Doug
If you do not have the ability to modify your php.ini file, use cURL: PHP Curl And Cookies
如果您无法修改 php.ini 文件,请使用 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;
}
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.
注意:在重新访问此函数时,我注意到我在此代码中禁用了 SSL 检查。这通常是一件坏事,即使在我的特殊情况下,我使用它的站点是本地的并且是安全的。因此,我修改了此代码以默认启用 SSL 检查。如果由于某种原因您需要更改它,您可以简单地更新 CURLOPT_SSL_VERIFYPEER 的值,但如果有人使用它,我希望代码在默认情况下是安全的。
回答by Ahmad
Use this code in your php script (first lines)
在您的 php 脚本中使用此代码(第一行)
ini_set('allow_url_fopen',1);
回答by AndiPower
Edit your php.ini, find allow_url_fopen and set it to allow_url_fopen = 1
编辑你的 php.ini,找到 allow_url_fopen 并将其设置为 allow_url_fopen = 1
回答by Fran?ois Roduit
Using relativeinstead of absolute file path solved the problem for me.
I had the same issue and setting allow_url_fopen=ondid not help. This means for instance :
使用相对而不是绝对文件路径为我解决了这个问题。我有同样的问题,设置allow_url_fopen=on没有帮助。这意味着例如:
use
$file="folder/file.ext";instead of
$file="https://website.com/folder/file.ext";in
使用
$file="folder/file.ext";而不是
$file="https://website.com/folder/file.ext";在
$f=fopen($file,"r+");
回答by Sanjay Sikdar
THIS IS A VERY SIMPLE PROBLEM
这是一个非常简单的问题
Here is the best method for solve this problem.
这是解决此问题的最佳方法。
Step 1 : Login to your cPanel (http://website.com/cpanelOR http://cpanel.website.com).
第 1 步:登录您的 cPanel(http://website.com/cpanel或http://cpanel.website.com)。
Step 2 : SOFTWARE -> Select PHP Version
第 2 步:软件 -> 选择 PHP 版本
Step 3 : Change Your Current PHP version : 5.6
第 3 步:更改您当前的 PHP 版本:5.6
Step 3 : HIT 'Set as current' [ ENJOY ]
第 3 步:点击“设为当前”[享受]

