title: Why do my cookies expire instantly?
body: <p>I have a function that sets cookies; in this function I use PHP's <code>setcookie</code> function in order to set cookies, for example:</p>
  
  <pre><code>setcookie('auth', $token, time() + 3600);
  </code></pre>
  
  <p>The function I'm using <code>setcookie</code> in is as follows:</p>
  
  <pre><code>function SetAuthenticationCookie($id, $rememberme) {
      $token = md5(uniqid(mt_rand(), true));
      executeNonUserQuery([db query]);
      if ($rememberme) {
          setcookie('auth', $token, time() + (86400 * 90));
          setcookie('profid', $id, time() + (86400 * 90));
      }
      else
      {
          setcookie('auth', $token, time() + 3600);
          setcookie('profid', $id, time() + 3600);
      }
  }
  </code></pre>
  
  <p>The above cookie should be valid for one hour, and appears this way in the browser (see below screenshot).</p>
  
  <p>In the browser the cookies show before it redirects (the page is dynamic), therefore the cookies <em>are</em> being set. However they disappear when the page redirects. This causes a problem because the main UI page (where the login page redirects) checks for the presence of the authentication cookies and redirects back to the login page if they don't exist.</p>
  
  <p><a href="https://i.stack.imgur.com/UjlFUm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UjlFUm.png" alt="enter image description here"></a></p>
  
  <p>I followed the <a href="http://php.net/manual/en/function.setcookie.php" rel="nofollow noreferrer">official documentation for <code>setcookie</code></a> and am unable to see what the problem is. Chrome reports that the cookie path is <code>/internal</code> therefore it's a possibility that the actual page can't access them (the page path is <code>/pages</code>), but this still doesn't explain why they disappear completely from Chrome.</p>
  
  <p>The cookie is set to expire in an hour after it is set, but this doesn't explain the disappearance of the cookies unless I'm missing something crucial in <code>setcookie</code> concerning the setting of the expiration time. I experience the same issue in other browsers, so it has to be something that I've done wrong or missed.</p>
  
  <p>I confirm that I have nothing that unsets or expires the cookies (I haven't implemented that yet). I've tried setting the path to <code>/</code> but this doesn't fix the problem.</p>
  
  <p>What am I doing wrong, and how can I fix it?</p>
  
  <p><em>I'm aware of the security issues here, my priority is to fix this problem first.</em></p>