title: Using setcookie in body content
body: <p>In PHP manual for <code>setcookie()</code> (<a href="http://php.net/manual/en/function.setcookie.php" rel="nofollow noreferrer">http://php.net/manual/en/function.setcookie.php</a>) we learn that cookie is sent along with the rest of HTTP headers. This means it has to be sent before any output from the script, including html and head tags.</p>
  
  <p>To my suprise below code is working fine:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;title&gt;Cookie test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;p&gt;Proin ornare sapien in justo laoreet imperdiet. Duis bibendum iaculis dui id consequat. Interdum et malesuada fames ac ante ipsum primis in faucibus.&lt;/p&gt;
      &lt;?php
      setcookie('test_cookie', uniqid(), time()+3600);
      ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>As you can see the <code>setcookie()</code> function is called inside the body tag. I use Chrome dev tools to view current cookies and the <code>test_cookie</code> is listed.
  <a href="https://i.stack.imgur.com/ySHhZ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ySHhZ.jpg" alt="enter image description here"></a></p>
  
  <p>Why does the above code doesn't trigger any error message from the PHP ?</p>
  
  <p>I'm using XAMPP 3.2.2, PHP Version 7.0.9, Chrome 62.0.3202.94</p>