PHP如何排除我要包含的文件中包含的文件?

问题描述 投票:0回答:2

假设我要包含header.php文件,并且header.php已经包含另一个包含functions.php的文件。如果在index.php中包含header.php,那么functions.php自然也将包含在内。但是,如果出于某些特定原因我想断开关节并在包括functions.php时排除header.php,该怎么办?这可能吗?

php include require
2个回答
0
投票

您可以更改为:

include_once 'functions.php';

因此即使Header.php和Index.php拥有它,它也只会包含一次。


0
投票

由于经过大量搜索,我找不到本机的PHP函数,因此我想到的解决方法是:

if(basename($_SERVER['PHP_SELF']) != 'page-name.php'){ 
  include('functions.php'); 
} 

使用此代码,functions.php将包含在header.php中的所有页面中,只有page-name.php上除外

© www.soinside.com 2019 - 2024. All rights reserved.