Cookie没有用PHP编写,即使它显示在Response标头中

I'm making an AJAX call on my website to a login page and (trying to store) a cookie using setcookie(). When I see the request headers in Chrome inspector, I can see the correct Request Headers but the cookie is not being stored.

What could I possibly be doing incorrectly? (I am not doing any output at all)

Are you sure your PHP code is not doing any output at all. Not even 1 teensy weensy blank character (perhaps just before your first <?php tag).

Because if PHP writes even a single character of the response body, it can no longer write HTTP headers ... which is what setcookie must do in order to create a cookie.

Another possibility, quoting from the PHP doc for setcookie

Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. Expire time is set via the expire parameter. A nice way to debug the existence of cookies is by simply calling print_r($_COOKIE);.

(If this still is not it, show us your exact and entire code with setcookie. We need more info to be of help.)

Problem solved. This was a part of a complex project.

I had to go and look at the local cookies on my Chrome (rather than in the headers alone, or just using the editthiscookie plugin for Chrome.)

Long story short, there was bad cookie logic in javascript code that was stomping on my cookie, but THANKS FOR YOUR HELP!