title: PHP cookie in Wordpress returns null value when logged in
body: <p>Hi I've got a button click event that uses admin-ajax.php to call up a function in my function.php I set a cookie and try to append an id to the existing cookie value (list of ids).</p>
  
  <p>I'm using admin-ajax.php outside of a plugin very similar to this article <a href="https://premium.wpmudev.org/blog/using-ajax-with-wordpress/" rel="nofollow">https://premium.wpmudev.org/blog/using-ajax-with-wordpress/</a></p>
  
  <p>But when I'm logged in as the admin the <code>$_COOKIE[$name]</code> always returns <code>Null</code>. However when I log out and return as a visitor everything is working correctly. I want this function to work for all users regardless if they are logged in or not. Can someone help me figure out what I'm doing wrong?</p>
  
  <p><strong>in my Javascript:</strong></p>
  
  <pre><code>$.ajax({
          url : myObj.ajax_url,
          type : 'post',
          data : {
              action : 'store_this_id',
              post_id : post_id
          },
          success : function( response ) {
              console.log(response);
          }
      });
  </code></pre>
  
  <p><strong>in fuctions.php:</strong></p>
  
  <pre><code>add_action( 'wp_ajax_nopriv_store_this_id', 'store_this_id' );
  add_action( 'wp_ajax_store_this_id', 'store_this_id' );
  
  function store_this_id() {
      $name = "mycookie";
      $expire = time() + (60*60*24); // expire in 24 hours
      $value = isset( $_COOKIE[$name] ) ? $_COOKIE[$name] : "test";
      $value .= "," . $_POST['post_id'];
  
      if ( defined( 'DOING_AJAX' ) &amp;&amp; DOING_AJAX ) {
          setcookie($name, $value, $expire, '/');
          $_COOKIE[$name] = $value;
  
          print_r($value);
          echo "\n";
          print_r($_COOKIE[$name]);
      }
      die();
  }
  </code></pre>
  
  <p><strong>Console output [logged out] running two tests:</strong></p>
  
  <pre><code>XHR finished loading: POST "http://mywebsite.dev/wp-admin/admin-ajax.php"
      test,1741
      test,1741
  XHR finished loading: POST "http://mywebsite.dev/wp-admin/admin-ajax.php"
      test,1741,1760
      test,1741,1760
  </code></pre>
  
  <p><strong>Console output [logged in as admin] running the same two tests:</strong></p>
  
  <pre><code>XHR finished loading: POST "http://mywebsite.dev/wp-admin/admin-ajax.php"
      null,1741
      null,1741
  XHR finished loading: POST "http://mywebsite.dev/wp-admin/admin-ajax.php"
      null,1760
      null,1760
  </code></pre>