doufang1889
2014-04-25 06:17
浏览 404
已采纳

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

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

  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=1 in the php.ini and that worked but I don't think that everybody will let me change their php.ini file.

So, is there any way to accomplish this?

图片转代码服务由CSDN问答提供 功能建议

我试图通过

 <在页面中包含一个php文件 code> require_once(http://localhost/web/a.php)
   
 
 

我收到错误

 < 代码>警告:require_once():http://在服务器配置中禁用包装器allow_url_include = 0 
   
 
 

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

那么,有什么办法可以实现这个目标吗? / p>

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

8条回答 默认 最新

  • dougu4027 2014-04-25 06:26
    已采纳

    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:

    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).

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dtx9931 2014-04-25 06:21

    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)

    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');
    
    评论
    解决 无用
    打赏 举报
  • douqiu0796 2015-10-06 15:38

    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.

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

    评论
    解决 无用
    打赏 举报
  • douweibiao8471 2016-04-22 12:07

    try to use

    <?php require_once($_SERVER['DOCUMENT_ROOT'].'/web/a.php'); ?>
    
    评论
    解决 无用
    打赏 举报
  • drtoclr046994545 2018-01-19 09:49
    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.

    评论
    解决 无用
    打赏 举报
  • dongni3854 2018-02-07 19:24
    require_once(APPPATH.'web/a.php');
    

    worked for me in codeigniter

    check reference

    评论
    解决 无用
    打赏 举报
  • douzhanlai4671 2018-08-10 07:57

    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.INI file
    Find 'allow_url_include'
    replace it with value 'on'
    allow_url_include=On
    Save you php.ini & RESTART you web-server.

    评论
    解决 无用
    打赏 举报
  • dsm42026 2019-03-30 09:58

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

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题