1

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 ?

4

4 回答 4

1

in 的路径include总是相对于顶级脚本。因此,您的第二个(嵌套)包含将无法正确解析。

一个常见的解决方法是使用:

<?php
include dirname(__FILE__)."/config.php";
?>

里面includes/global.php。这将使路径正确解析,无论顶层脚本位于何处。

于 2013-04-26T10:47:59.480 回答
1

检查您的include_path。您需要添加“。” 给它。

或者您可以在运行时定义它。

set_include_path(get_include_path() . PATH_SEPARATOR . '.');
于 2013-04-26T10:49:14.287 回答
0

global.php,

include "includes/config.php";
于 2013-04-26T10:50:48.423 回答
0

我遇到了同样的问题,但真的不想使用解决方法,所以我尝试了一些方法,发现我正在处理的代码是用旧式 php 开始标记编写的,即<?

一旦我将其更改为<?php包含工作。

于 2016-08-16T18:37:22.340 回答