title: When to send HTTP status code?
body: <p>Currently in my PHP scripts, I redirect the user to a custom 404 not found error page when he/she tries to access content that doesn't exist or doesn't belong to that user. Like so:</p>
  
  <pre><code>header('Location: http://www.mydomain.com/error/notfound/');
  exit;
  </code></pre>
  
  <p>I realize the above header() call sends a 302 redirect status code by default.</p>
  
  <p>What I don't understand, however, is when I should send the 404 not found status code. Before I redirect the user? Or when I display the <em>/error/notfound/</em> page?</p>
  
  <p>Thanks for your help!</p>