title: PHP: Should setcookie() be called before *any* other page content?
body: <p>I´m reading that the setcookie() function adds HTTP headers to any page, and thus must be called before any of the actual page content is sent. That makes sense to me.</p>
  
  <p>But after that, there´s this example:</p>
  
  <pre><code>&lt;?php
  if (!isset($_COOKIE['visits'])) { $_COOKIE['visits']=0; }
  $visits= $_COOKIE['visits'] +1;
  setcookie('visits', $visits, time() + 3600);
  
  include 'welcome.inc.php'
  
  ...
  </code></pre>
  
  <p>I mean, if setcookie() mus be first, shouldn´t it be:</p>
  
  <pre><code>setcookie('visits', $visits, time() + 3600);
  $visits= $_COOKIE['visits'] +1;
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>$visits= $_COOKIE['visits'] +1;
  setcookie('visits', $visits, time() + 3600);
  </code></pre>
  
  <p>It´s a very newbie question, but can´t quite understand the example in relation to the need of calling setcookie() before everything.</p>