title: PHP Delete File if other file exists
body: <p><em>Note: The file number is just so I can refer to each file easier</em></p>
  
  <p>I am testing some code in which I have a file called <code>first.txt</code> (file 1) and and file called <code>tom-first.php</code> (file 2), file 2 file checks for the file 1's existence and sets a variable, then in my <code>index.php</code>(file 3), I require file 2 and if the variable is 1, I redirect to <code>startup.php</code>(file 4). File 4 deletes a text file called <code>text.txt</code></p>
  
  <p>My error is when I run the code, no matter what happens, test.txt is always deleted</p>
  
  <p><strong>tom-first.php</strong></p>
  
  <pre><code>&lt;?php
  
  if (file_exists('first.txt')) {
      $first = '1';
  } else {
      $first = '0';
  }
  
  echo $first;
  ?&gt;
  </code></pre>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>&lt;?php
  require 'tom-first.php';
  if($first = '1')
  {
      header("Location: startup.php");
  }
  else
  {
      echo 'HI';
  }
  
  
  ?&gt;
  </code></pre>
  
  <p><strong>Startup.php</strong></p>
  
  <pre><code>&lt;?php
  unlink('text.txt') 
  ?&gt;
  </code></pre>
  
  <p><strong>First.txt is Empty</strong></p>
  
  <p>I feel like the error is to do with setting variables on file 2 although echoing out $first shows the right number.</p>
  
  <p>Any help is appreciated, even a completely different method of this would be useful, I am basically trying to make a system where it has a setup that runs on first time use.</p>