我使用这个if语句来重定向用户,如果在。txt文档中的值是0,但如果它是1,我不想发生任何事情,但是我的代码有一些问题。
这是我当前的代码:
$setup = require('setup.txt');
if ($setup === "0") {
echo '<script type="text/javascript"> window.location = "setup.php" </script>';
}
setup.txt文档当前包含值0。
我想看看require函数的正确用法。
if (file_get_contents('setup.txt') == "0") {
header('Location: /setup.php');
}
如果您还没有向浏览器发送输出,请使用header函数。
$setup = file_get_contents('setup.txt');
if ($setup == "0") {
header('Location: /setup.php');
}
因为所有PHP都是在输出站点之前执行的。请先使用此选项。
您不能像您那样使用include()
/require()
作为变量来传输。使用file_get_contents()
达到效果。
try this:
<?php
$setup = file_get_contents('setup.txt');
if (trim($setup) == "0") {
echo '<script type="text/javascript"> window.location = "setup.php" </script>';
}
?>