title: Attempting to set and get Cookie - Causing undefined index error
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index">PHP: “Notice: Undefined variable”  and “Notice: Undefined index”</a>  </p>
  </blockquote>
  
  
  
  <p>I just have a quick question about an error I received when I attempted to set and retrieve value of a cookie in PHP.</p>
  
  <p>From this site and others, the following codes are the ones I am using to achieve this:</p>
  
  <pre><code>     &lt;?php
       setcookie("edgeUser", $_POST['userName'], time()+0);
       echo $_COOKIE['edgeUser'];
       ?&gt;
  </code></pre>
  
  <p>From what I understand, this will set a cookie with name="edgeUser", value="$userName" (which is provided from another page that is HTML), and will expire the moment that the user closes the session.</p>
  
  <p>However, when I did run this, I got an error that apparently occurred on the "echo" line:</p>
  
  <pre><code>     Notice: Undefined index: edgeUser in C:\wamp\www\Login2.php on line **
  </code></pre>
  
  <p>Am I supposed to define "edgeUser" somewhere else in the code? I attempted to look into this, however, I either didn't see or didn't understand what else I am supposed to do.
  Any help would be greatly appreciated!</p>