Understanding Cookies in PHP
<p>When the following code is run for the first time, it does not echo out the "var1" value but it does on browser refresh (f5), Why? As i understand when the browser sends the code to the server, setcookie() stores the cookie variable ("var1") to a client (browser) in a local file and puts the "var1" value available in global domain via $_COOKIE superglobal. </p>

<p>Since "var1" value is available immediately in $_COOKIE after the first server replies to browser's initial request, then  why the "var1" is not echoed out. Is it that setcookie() stores "var1" value in client's browser on first request and only when the page is refreshed (2nd request) the browser sends back "var1" value to the server and then the server makes it available in the global domain via $_COOKIE function.</p>

<hr>

<h2> CODE</h2>

<pre><code>&lt;?php
  setcookie("var1","5");
  echo $_COOKIE['var1'];
?&gt;
</code></pre>

<p>Kindly clear this for me. </p>

<p>Thanks
djain.</p>
