title: Cookies during ajax call different from cookie on page that makes the ajax call
body: <p>First of all, this is all happening on the same base domain, and I'm not making any ajax calls off site to a different URL.</p>
  
  <p>I'm making a simple ajax call every 10 seconds from any page on my site to a php class, and based on the user information in the cookies which is assigned when the user is logged in, it will update a last_active datetime value to the current timestamp in the database for that user.  This is mainly used for displaying on a page I made of users who currently have the site open on their screen.</p>
  
  <p>I noticed that if I log out on one user, then log in as a different user, the cookie updates fine after logging in.  However, it seems when I make the same ajax call to update the last_active datetime, it is updating the previously logged in user's time instead.</p>
  
  <p>I found that during the ajax call and only during the ajax call, the cookies still contained the previous logged in user's information.</p>
  
  <p>I've never had this problem before, so I'm unsure what is causing it or how to fix it without requiring another ajax call to manually set the cookie to the right user.</p>
  
  <p>As for sample code, I guess this is the best way I can give an example.</p>
  
  <p>On my index.php, I included a script index.js.  In the script, I have it making an ajax call every 10 seconds to a php script in the app folder.</p>
  
  <pre><code>$.ajax({
      type: "POST",
      url: "app/ajax.php",
      data: {
          'class': 'App_User',
          'function': 'updateLastActive',
          'user_account_id': user_account_id
      },
      dataType: "json",
      success: function(data) {
      }
  });
  </code></pre>
  
  <p>The above code will make a call to the app/ajax.php with the given data values.  Basically in ajax.php, it will initiate the App_User class then run the updateLastActive function with the user_account_id as an argument.</p>
  
  <p>As I mentioned, the whole ajax calling process works fine.  The only problem is, for example, if I do a var_dump($_COOKIE) from within the App_User class during the ajax call, versus if I did a var_dump($_COOKIE) from index.php before or after the ajax call, the information is different.</p>
  
  <p>From the front end perspective, here is what I see when tracing the cookie info.</p>
  
  <ol>
  <li>I log into the site as user A, whose user_account_id is 12</li>
  <li>The var_dump from index.php shows user_account_id as 12, which is correct.</li>
  <li>Ajax call is made, the var_dump from within the App_User class during the call shows user_account_id as 12, which is correct.</li>
  <li>I log out, then log back into the site as user B, whose user_account_id is 10</li>
  <li>The var_dump from index.php shows user_account_id as 10, which is correct</li>
  <li>Ajax call is made, the var_dump from within the App_User class during the call shows user_account_id as 12.</li>
  </ol>