title: php setcookie() not working correct
body: <p>I'm trying to get the hang of how setcookie() works in php so i made i simple script for testing purposes. The only thing the script does is ask for a username and then makes a cookie for it. when you enter the same username again it should welcome you back. if it is the first time you entered that username it should welcome you for the first time. Here's what i did:</p>
  
  <p>This is the form;</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="nl"&gt;
  &lt;head&gt;
  &lt;title&gt;XXL Computer winkel&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h3&gt;php lab 12&lt;/h3&gt;
  &lt;table border=0 cellpadding=0 cellspacing=0 &gt;
  &lt;form name="orderform" action="&lt;?php echo $_SERVER['PHP_SELF'];?&gt;" method="post"&gt;
  &lt;tr&gt;
  &lt;td&gt;gebruikersnaam&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="user" /&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="submit" name="send" value="inloggen" /&gt; &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/form&gt;
  &lt;/table&gt;
  &lt;?php
  
  include ("cookiefuncties.php");
  
  welkom();
  
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>cookiefuncties.php looks like this:</p>
  
  <pre><code>&lt;?php
  
  function welkom()
  {
  
  if(isset($_POST['user']))
  {
      $cookie_value = $_POST['user'];
      $cookie_name = "gebruikersnaam";
      setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); 
  }
  if(isset($_POST['user'])&amp;&amp; $_COOKIE[$cookie_name] === ($_POST['user']))
      {
  
          echo "Welcome back " . $_COOKIE[$cookie_name] . "!";
      }
  if(isset($_POST['user'])&amp;&amp; $_COOKIE[$cookie_name] != ($_POST['user']))
      {
  
          echo "Welcome " . $_COOKIE[$cookie_name] . "This is your first visit";
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>Problem is that the cookie is always 'one name late'. Therefore i need to refresh the page and it will always welcome the user back instead of saying it's the first visit. I know there is an option to 'force' a refresh but i don't know how, and if that is the solution.</p>
  
  <p>Greetings,
  Lennart</p>
  
  <p>ps. Don't mind the spacings. I still don't know how to get that right on this site :-(</p>