title: header('location:...) doesnt behave right in combination with if clause
body: <pre><code>if(isset($_POST))
  {
    if(verify_post_data() == 'success')
    {
      if(do_something_with_verified_post_data() == 'success')
      {
      //do something else
      header('location: success.php');
      }
    }
    header('location: failure.php');
  }
  </code></pre>
  
  <p>I want to process the data a user has posted in multiple steps (first verify if everything's correct, then do something with the data).</p>
  
  <p>If verification of the post data and doing something with it has been successful, I want to redirect the user to success.php</p>
  
  <p>If verification failed, or if doing something with the data failed, I want to redirect to failure.</p>
  
  <p>here's what's happening:</p>
  
  <p>when i remove the header(...) functions by commenting and instead I say </p>
  
  <pre><code>//header('location: success.php');
  echo 'success!';
  </code></pre>
  
  <p>and</p>
  
  <pre><code>//header('location: failure.php');
  echo 'failure!';
  </code></pre>
  
  <p>My script will print "success!failure!" if my data was correct and no errors happened when doing something with the data. Makes perfect sense... Because the echoing of success didn't interrupt the script, failure will still be displayed.</p>
  
  <p>so when I uncomment the success header (failure header stays commented), it does indeed send me to success.php</p>
  
  <p>if I then also uncomment the failure header, it will now - even upon success - send me to failure.php.</p>
  
  <p>How is that possible?</p>
  
  <p>I expect the header function to interrupt the script and ignore any code that comes after it. Is my assumption wrong? Do I have to somehow exit the script manually?</p>
  
  <p>Doesn't php process the code line by line? or does it do the headers in the curly brackets last and other headers first, or what?</p>
  
  <p>Or should this not be happening and I must be having an error somewhere else?</p>