title: How can I set a cookie and then redirect in PHP?
body: <p>After doing a bit of processing, I want to set a cookie value to user input and then redirect them to a new page.  However, the cookie is not getting set.  If I comment out the redirect, then the cookie is set successfully.  I assume this is a header issue of some sort.  What is the best workaround for this situation?</p>
  
  <pre><code>if($form_submitted) {
      ...
      setcookie('type_id', $new_type_id, time() + 60*60*24*30);
      header("Location: $url");
      exit;
  }
  </code></pre>
  
  <p>Note that setcookie returns <code>true</code> in either case and I get no errors/warnings/notices.</p>
  
  <p><strong>EDIT:</strong> I am using Unix/Apache/MySQL/PHP</p>