简体   繁体   English

如何将一个PHP文件的内容包含在另一个主文件中?

[英]How to include the content of one PHP file in another master file?

//Grab and assign List ID from confirmation URL 
$L = $_GET["L"]; 

//Set Redirects based on List ID  
if($L == "1") { 
header("Location: http://stat.domain.com/");
exit();
}  

This is the content of a redirection rule that I have created, but I am thinking of putting these in a separate file instead of the master file MASTER.php. 这是我创建的重定向规则的内容,但是我正在考虑将它们放在单独的文件中,而不是主文件MASTER.php中。 I was reading online and there are different ways of reading the content off a separate file, of which are functions like include() include_once(). 我在网上阅读,并且有不同的方法可以读取单独文件中的内容,其中包括诸如include(),include_once()之类的功能。 However, after reading through some information online, i am still not very sure what i should do to include the above content in the master file. 但是,在在线阅读了一些信息之后,我仍然不太确定如何将上述内容包括在主文件中。

Any efficient way of doing this? 有任何有效的方法吗?

You only want to include that file once in a certain place. 您只希望在某个位置包含一次该文件。 Perhaps add an include to redirects.php from master.php : 也许添加一个包含到master.php redirects.php

require_once 'redirects.php';

You could also use include_once , but that will not halt the script if the file cannot be found and will fail silently - which is usually much worse than explicitly. 您也可以使用include_once ,但是如果找不到该文件并且该脚本将以静默方式失败,则不会暂停脚本-通常比显式更糟糕。

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

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