0

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.

8
  • so check if it equals 1 n'est-ce pas? Commented Sep 6, 2015 at 16:47
  • I have tried '=' '==' and '===' but still not working Commented Sep 6, 2015 at 16:49
  • you're checking for a string, rather than an integer; seems like it to me. Harder to say without seeing what's inside that text file of yours. anyway, see the answers below. I'm not submitting an answer. Commented Sep 6, 2015 at 16:49
  • the document just has the number 0 Commented Sep 6, 2015 at 16:51
  • 2
    where are we with the question; none of the answers worked? Plus, if your file contains a space/spaces or a carriage return, that may also affect its proper execution/success. Commented Sep 6, 2015 at 17:12

3 Answers 3

2

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

if (file_get_contents('setup.txt') == "0") { header('Location: /setup.php'); } 
Sign up to request clarification or add additional context in comments.

Comments

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.

2 Comments

Still doesn't seem to redirect the page
Yeah that was my bad, I updated the answer, after realizing the you where actually including the file itself.
0

try this:

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

Comments