所以我想做的一个例子。
主.php
<?php
require_once("setup.php")
setup();
?>
设置.php
<?php
function setup() {
require_once("other.php") // Requires this file in main.php not setup.php
header("Access-Control-Allow-Origin: *"); // This header to also effect main.php not setup.php
}
?>
其他.php
<?php
// Stuff that main.php needs but must be part of the setup function
?>
将所有内容从require_once更改为要求似乎已经解决了所有问题。