运行脚本时出现以下错误。该错误消息是如下...服务器配置allow_url_fopen = 0
警告:file_get_contents()函数[function.file-GET-内容]:https://开头包装纸在服务器配置中禁用于allow_url_fopen = 0 /家/ satoship /public_html/connect.php on line 22
我知道这是一个服务器问题,但为了摆脱上述警告我需要做些什么来服务器?
运行脚本时出现以下错误。该错误消息是如下...服务器配置allow_url_fopen = 0
警告:file_get_contents()函数[function.file-GET-内容]:https://开头包装纸在服务器配置中禁用于allow_url_fopen = 0 /家/ satoship /public_html/connect.php on line 22
我知道这是一个服务器问题,但为了摆脱上述警告我需要做些什么来服务器?
如果你没有修改php.ini文件的能力,使用卷曲: PHP Curl And Cookies
这里是一个例如功能我创建:
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的值,但是如果有人使用它,我希望代码在默认情况下是安全的。
@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;
?>
使用此代码在您的PHP脚本(第一行)
ini_set('allow_url_fopen',1);
我在我的根目录(public_html)中创建了一个空的php.ini文件,它的工作原理是:) – Ahmad
此工作适用于4.3.4或更早版本。 4.3.4后''allow_url_fopen'必须在php.ini中注册 http://php.net/manual/en/ini.list.php –
这是一个非常简单的问题
这是解决此问题的最佳方法。
步骤1:登录到您的cPanel(http://website.com/cpanel或http://cpanel.website.com)。
步骤2:软件 - >选择PHP版本
第3步:改变当前的PHP版本:5.6
第3步:HIT '设置为当前'[ENJOY]
变化的php.ini 'allow_url_fopen = on'; p –
我已经完成了这个工作,但还没有解决问题。我有权访问服务器,但我不知道该怎么做才能打开它 – JohnThomas
不要忘记重新启动apache'sudo service apache2 restart' –