PHP重定向if语句

I am using this if statement to redirect a user if the values in a .txt document is 0 but if it is 1 I want nothing to happen however I'm having some issues with my code.

This is my code currently:

$setup = require('setup.txt');

if ($setup === "0") {
    echo '<script type="text/javascript"> window.location = "setup.php"    </script>';
}

The setup.txt document currently contains the value 0.

Use the header function if you have not already sent output to the browser.

$setup = file_get_contents('setup.txt');
if ($setup == "0") {
  header('Location: /setup.php');
}

Since all PHP is executed before the output the site. Use this option first.

You can not use include() / require() to transfer as a variable, like you have. Use file_get_contents() to achieve the results.

I'd look here as to the proper usage of the require function.

if (file_get_contents('setup.txt') == "0") {
      header('Location: /setup.php');
}

try this:

<?php
 $setup = file_get_contents('setup.txt');
 if (trim($setup) == "0") {
   echo '<script type="text/javascript"> window.location = "setup.php"    </script>';
 }
?>