繁体   English   中英

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

[英]PHP How to exclude a file which is included in the file I am including?

假设我想包含header.php文件,而header.php已经包含另一个包含functions.php的文件。 如果在我的index.php中包括header.php那么自然functions.php 。php 也会被包括在内。 但是,如果由于某些特定原因我想打破联合并排除functions.php而包括header.php怎么办? 这可能吗?

由于经过大量搜索我找不到本地 PHP function 我想出的解决方法是:

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

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

您可以更改为:

include_once 'functions.php';

所以它只会包含一次,即使 Header.php 和 Index.php 有它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM