我有点小问题。下面是我的例子:
文件1.php:
<?php include("file2.php"); ?>
文件2.php:
<?php header("Location: file1.php"); ?>
因为包含了file2.php,重定向过程将永远不会结束。但我仍然希望file2.php重定向到file1.php,还需要在file1.php中包含file2.php。
听起来可能有点复杂,但我认为可以解决。
如有任何帮助,我们将不胜感激。
提前谢谢。
谨致问候,
阿克斯
最佳答案
将重定向语句包装在if语句中,如下所示:
// file2.php
<?php
if ($_SERVER['PHP_SELF'] == "file2.php") {
header("Location: file1.php");
}
?>
您还可以检测包含以下内容:
if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME']) {
// Not Included
} else {
// Included
}
关于php - 如何解决不断发展的重定向过程?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6758641/