Warning: require_once(): http:// wrapper is disabl

2019-01-07 11:11发布

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?

标签: php include
7条回答
三岁会撩人
2楼-- · 2019-01-07 11:36

try to use

<?php require_once($_SERVER['DOCUMENT_ROOT'].'/web/a.php'); ?>
查看更多
Evening l夕情丶
3楼-- · 2019-01-07 11:41

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.

查看更多
Rolldiameter
4楼-- · 2019-01-07 11:42
require_once(APPPATH.'web/a.php');

worked for me in codeigniter

check reference

查看更多
何必那么认真
5楼-- · 2019-01-07 11:43

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.

查看更多
Root(大扎)
6楼-- · 2019-01-07 11:46
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.

查看更多
三岁会撩人
7楼-- · 2019-01-07 11:55

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');
查看更多
登录 后发表回答