title: PHP Cookies and Visit Counter
body: <p>I am trying to learn php (brand new) and I am trying to achieve the exact same thing found in this post which is using cookies for a counter and last visits on a website:</p>
  
  <p><a href="https://stackoverflow.com/questions/36543611/php-cookie-visit-counter-not-working">PHP cookie visit counter not working</a></p>
  
  <p>but unlike the user in that post I am running into this infamous error:</p>
  
  <p>"It's your first time on the server! Warning: Cannot modify header information - headers already sent by (output started at  in (...) on line 17</p>
  
  <p>This is line 17: setcookie('visitCount1');</p>
  
  <p>Now I realized this is common and searched SO and found this post: </p>
  
  <p><a href="https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php">How to fix &quot;Headers already sent&quot; error in PHP</a></p>
  
  <p>I thoroughly read and went through the possible reasons for why this might be occurring, including white spaces and inputting the noted php lines mentioned by my browser prior to any html code and also removing the end tag "?>" AND I as well tried putting ob_start() in the beginning of my code but still the same error results. </p>
  
  <p>Here is the code that I am trying to run (taken from the above post):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  $Month = 3600 + time();
  
  date_default_timezone_set('EST');
  setcookie('AboutVisit1', date("D M j G:i:s T Y"), $Month);
  ?&gt;
  
   &lt;?php
  if(isset($_COOKIE['AboutVisit1']))
  {
  $last = $_COOKIE['AboutVisit1'];
  echo "Welcome back! &lt;br&gt; You last visited on ". $last . "&lt;br&gt;";
  
  
  }
  if(isset($_COOKIE['visitCount1'])){
  
  
   $cookie = ++$_COOKIE['visitCount1'];
  
  
   echo ("You have viewed this page" . $cookie . "times.");
  }
  else
  {
  echo "It's your first time on the server!";
  setcookie('visitCount1');
  }
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I am using netbeans 8.1 with wamp server and chrome as my browser. What else can be done to solve this? </p>
  
  <p>Is it actually possible to see the cookies and track record of sessions if I am just testing this on my browser or through netbeans?</p>
  
  <p>Do I have to include an html header and body or can I just put it in the php body? </p>
  
  <p>On php fiddle it works (somewhat) and I get this (always the same time):</p>
  
  <p>Welcome back! 
  You last visited on Tue Aug 9 15:43:00 EST 2016
  It's your first time on the server!</p>