I am using following syntax to set cookie:

Set-Cookie:Cookie-name=value; path=/; Max-Age=1296000; HttpOnly

In google chrome console it is showing Invalid Date for that cookie.

What is wrong in the syntax ?

According to http://en.wikipedia.org/wiki/HTTP_cookie#Expires_and_Max-Age http://tools.ietf.org/html/rfc6265#section-5.2.2 I can use Max-Age to specify relative expiration time.

有帮助吗?

解决方案

I don't think it is something which you could/should solve. The Inspector/Dev tool that you are using is not always right as shown by the other user. There are other cases where the Dev tool is wrong too, like in "network" tool.
You could install an extension like edit this cookie to find out how your cookies are behaving. Although it doesn't help you track across redirects, it helps knowing what cookies are set up and allows you to change it too.

其他提示

Update

I performed additional tests and came to the same conclusion as Issue 123013 listed below. I think this is just a DevTools bug.

DevTools > Network appears to incorrectly render the date. However, DevTools > Resources correctly displays the date similar to other browsers.

Also, another cookie I created correctly expired. This was reflected in DevTools > Resources but not in DevTools > Network. .

Test Results

setcookie('foo', 'bar', time()+3600, "/", NULL, false, true);

Chrome v24.0.1312.57
  Resources > Cookies   Thu, 14 Feb 2013 17:08:33 GMT
  Network > Cookies     Invalid Date

Firefox 18.0.2          Thursday, February 14, 2013 11:59:15 AM
IE9 9.0.8112.16421      Thu, 14-Feb-2013 17:06:42 GMT

Finally, to conclude, your syntax appears correct. The message "Invalid Date" looks like a Chrome bug.


I could not replicate this issue with Chrome v24.0.1312.57. I set various test cookies with JavaScript and PHP. Chrome threw no errors and correctly converted the max-age values I passed into a corresponding expires values.

This bug, or something very similar, has been submitted and apparently fixed.

WebKit

Chromium

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top