问题
My files structure are :
/ (Root)
|-- includes
|-- |-- global.php
|-- |-- config.php
|-- index.php
In my index.php
file I wrote :
<?php
include "includes/global.php";
?>
and in includes/global.php
I wrote :
<?php
include "config.php";
?>
the global.php
in index.php
will be include whitout any problem but config.php
in global.php
will not be include !
I use XAMPP and in my old version of XAMPP (version 1.7.3) I don't have any problem but today I installed new version of XAMPP (version 1.8.1) and I have this problem !
I should use absolute path for including config.php
file in global.php
but I don't want to use absolute path, I want to include like before, how can I do this ?
回答1:
Check your include_path. You need to add "." to it.
Or you can define it in runtime.
set_include_path(get_include_path() . PATH_SEPARATOR . '.');
回答2:
The path in include
is always relative to the top-level script. So your second (nested) include will not resolve correctly.
A common workaround is to use:
<?php
include dirname(__FILE__)."/config.php";
?>
inside includes/global.php
. This will make the path resolve correctly, no matter where the toplevel script is located.
回答3:
In
global.php,
write
include "includes/config.php";
回答4:
I was having the same issue, but don't really want to use a workaround, so I tried a few things and discovered that the code I'm working on is written with old style php opening tag, i.e. <?
As soon as I changed it to <?php
the includes worked.
来源:https://stackoverflow.com/questions/16234545/include-function-in-php-behaves-differently-on-xampp-update