title: undefined index on a session variable even though I have set a cookie
body: <p>I am trying to set cookies to a php session variable so that a session does not expire for 2 months. The problem I am getting though is that after about 3 hours, when I refresh the page, I get a undefined index for <code>$_SESSION['id']</code> in line 30. But I don't get the undefined index for <code>$_SESSION['id']</code> in between lines 20-23.</p>
  
  <p>Why am I still getting undefined indexes even though I have set cookies for this session variable?</p>
  
  <pre><code>$inTwoMonths = 60 * 60 * 24 * 60 + time();
      setcookie('id', 'ID', $inTwoMonths);
  
  
      //line 20-23
      if (isset($_POST['id'])) {
  
      $_SESSION['id'] = $_POST['id'];
  
      }
  
      //line 30
      &lt;?php echo $_SESSION['id'] ?&gt;
  </code></pre>