php 警告:require_once():http:// 包装器在服务器配置中被allow_url_include=0 禁用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23285503/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:37:43  来源:igfitidea点击:

Warning: require_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0

phpinclude

提问by Gags

I am trying to include a php file in a page via

我正在尝试通过在页面中包含一个 php 文件

  require_once(http://localhost/web/a.php)

I am getting an error

我收到一个错误

 Warning: require_once(): http:// wrapper is disabled in the server configuration by   allow_url_include=0

I changed allow_url_include=1in the php.ini and that worked but I don't think that everybody will let me change their php.ini file.

我更改allow_url_include=1了 php.ini 并且有效,但我不认为每个人都会让我更改他们的 php.ini 文件。

So, is there any way to accomplish this?

那么,有没有办法实现这一点?

回答by Nadeem Khan

The warning is generated because you are using a full URL for the file that you are including. This is NOT the right way because this way you are going to get some HTML from the webserver. Use:

生成警告是因为您正在使用包含的文件的完整 URL。这不是正确的方式,因为这样您将从网络服务器获取一些 HTML。用:

require_once('../web/a.php');

so that webserver could EXECUTE the script and deliver its output, instead of just serving up the source code (your current case which leads to the warning).

以便网络服务器可以执行脚本并提供其输出,而不仅仅是提供源代码(您当前的情况会导致警告)。

回答by keepyourreceipt

I had this same error while trying to include a PHP file in my Wordpress theme. I was able to get around it by referencing the file name using dirname(__FILE__). I couldn't use relative paths since my file was going to be included in different places throughout the theme, so something like require_once '../path-to/my-file'wouldn't work.

我在尝试在我的 Wordpress 主题中包含一个 PHP 文件时遇到了同样的错误。我能够通过使用dirname(__FILE__). 我无法使用相对路径,因为我的文件将包含在整个主题的不同位置,所以类似的东西require_once '../path-to/my-file'不起作用。

Replacing require_once get_template_directory_uri() . '/path-to/my-file'with require_once dirname( __FILE__ ) . '/path-to/my-file'did the trick.

更换require_once get_template_directory_uri() . '/path-to/my-file'require_once dirname( __FILE__ ) . '/path-to/my-file'的伎俩。

回答by keepyourreceipt

try to use

尝试使用

<?php require_once($_SERVER['DOCUMENT_ROOT'].'/web/a.php'); ?>

回答by SoftGuide

You have to put the path to the file. For example:

您必须输入文件的路径。例如:

require_once('../web/a.php');

You cannot get the file to require it from internet (with http protocol) it's restricted. The files must be on the same server. With Possibility to see each others (rights)

您无法从 Internet(使用 http 协议)获取文件以要求它受到限制。这些文件必须在同一台服务器上。有机会见到对方(权利)

Dir-1 -
         > Folder-1 -> a.php
Dir-2 -
         > Folder-2 -> b.php

To include a.php inside b.php => require_once('../../Dir-1/Folder-1/a.php');
To include b.php inside a.php => require_once('../../Dir-2/Folder-2/b.php');

回答by Anand agrawal

require_once('../web/a.php');

If this is not working for anyone, following is the good Idea to include file anywhere in the project.

如果这对任何人都不起作用,那么以下是在项目中的任何位置包含文件的好主意。

require_once dirname(__FILE__)."/../../includes/enter.php";

This code will get the file from 2 directory outside of the current directory.

此代码将从当前目录之外的 2 目录中获取文件。

回答by ziapcland

WORDPRESS is having this error mostly:
SOLUTION:
Locate your PHP installed directory on Remote live hosting SERVER or "Local Server"
In case of Windows os
for example if you using xampp or wamp webserver. it will be in xammp directory 'c:\xammp\php'
Note:For Unix/Linux OS, locate your PHP directory in Webserver

Find & Edit PHP.INIfile
Find 'allow_url_include'
replace it with value 'on'
allow_url_include=On
Save you php.ini& RESTARTyou web-server.

WORDPRESS 主要出现此错误:
解决方案:
在远程实时托管服务器或“本地服务器”上找到您的 PHP 安装目录 ,例如,如果您使用 xampp 或 wamp 网络服务器,则
在 Windows 操作系统的情况下
。它将位于 xammp 目录 'c:\xammp\php'
注意:对于 Unix/Linux 操作系统,在 Webserver

Find & Edit PHP.INI文件中找到您的 PHP 目录
查找'allow_url_include'
将其替换为值 'on'
allow_url_include=On
Save你php.ini&重新启动你的网络服务器。

回答by Devit Devitraj

echo file_get_contents('http://localhost/web/a.php'); //Best Example

echo file_get_contents(' http://localhost/web/a.php'); //最好的例子

回答by Edo Barrios Garrido

require_once(APPPATH.'web/a.php');

worked for me in codeigniter

在 codeigniter 中为我工作

check reference

检查参考