title: Cannot get cookie made in PHP in JavaScript file
body: <p>I am trying to get the username a user enters in an input box in a php file as a cookie, then in a JS file read that cookie and get the username.</p>
  <p>PHP</p>
  <pre><code>&lt;?php
  ...
     print('&lt;form method=&quot;POST&quot; name=&quot;loginForm&quot; action=&quot;myDomain.com&quot;&gt;' . &quot;\n&quot;);
     print('              &lt;div class=&quot;loginContainer&quot;&gt;' . &quot;\n&quot;);
     print('                              &lt;label for=&quot;userNameBox&quot;&gt;&lt;b&gt;Account Login: &lt;/b&gt;&lt;/label&gt;'. &quot;\n&quot;);
     print('          &lt;input type=&quot;text&quot; class=&quot;userName&quot;id=&quot;userNameBox&quot; placeholder=&quot;Enter Username&quot; required=&quot;required&quot;&gt;'. &quot;\n&quot;);
     print('          &lt;input type=&quot;button&quot; class=&quot;loginButton&quot; id=&quot;loginButton&quot; value=&quot;Login&quot;/&gt;' . &quot;\n&quot;);
     print('        &lt;/div&gt;'. &quot;\n&quot;);
     print('&lt;/form&gt;' . &quot;\n&quot;)
     print('     &lt;div id=&quot;toolbar&quot;&gt;' . &quot;\n&quot;);
  
  ...
  setcookie ( &quot;LOGIN_USERNAME_COOKIE&quot;, 
              $_POST['userNameBox'] , 
              $expires = 0, 
              $path = &quot;/&quot; , 
              $domain = 'myDomain.com' ,
              $secure = false,
              $httponly = false 
            );
  ...
  ?&gt;
  </code></pre>
  <p>JavaScript (just trying to print out the cookie)</p>
  <pre><code>confirm(&quot;Username entered: &quot;+document.cookie.split('LOGIN_USERNAME_COOKIE=')[1]);
  </code></pre>
  <p>In the confirm Java alert I get this:</p>
  <pre><code>Username entered: __utma=261946002.205893547.1618416838.1618416838.1618416838.1; __utmc=261946002; __utmz=261946002.1618416838.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmt=1; __utmb=261946002.1.10.1618416838; _fbp=fb.1.1618416838418.1117675244
  </code></pre>
  <p>how can I fix this to get the cookie to contain the text the user enters and display it?</p>