儘可能多的用戶的建議我我創建了一個文件globals.php
在那裏我:包括路徑,我可以出來這個
<?php
define('ROOT_DIR', __DIR__);
?>
,然後我包括在網站上的每個文件這個文件。
但現在問題出現時,我將此文件包含在其他文件。
E.g.網站結構:
/en/index.php
/header.php
/globals.php
現在,當我包括header.php
上index.php
<?php
//header.php
include 'globals.php';
//index.php
include '../globals.php';
include '../header.php';
?>
現在header.php
找不到globals.php'
因爲它搜索'../globals.php'
。
我該如何解決這個問題?
使用絕對路徑,而不是親戚? –
它不建議使用'<?php $ _SERVER ['DOCUMENT_ROOT']?>' 我應該總是寫例如:'__DIR __'。/ ../globals。php'; – Perocat
然後當我有兩次''../../''? – Perocat