20

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.

Vivek Goel
  • 22,942
  • 29
  • 114
  • 186
  • As per the Wikipedia page, if you'd followed the link to the RFC in question, it clearly states that not all useragents support max-age and will ignore it if found. – Marc B Feb 13 '12 at 05:46
  • @MarcB It is setting max-age as correct value in Google-chrome. I don't know then why it is showing "Invalid Date" – Vivek Goel Feb 13 '12 at 05:49
  • I am seeing the same issue in Chrome 17.0.963.56. The other issue I am seeing is that it doesn't show subsequent cookies in the same Set-Cookie header. – John Lemp Feb 22 '12 at 12:53
  • yep, seeing the same here. simple php setcookie('x','y',123+time(),'/','.domain.com'); shows up as invalid cookie. – Toby Feb 07 '13 at 12:13
  • What version of Chrome are you running? I could not replicate the error. – JSuar Feb 13 '13 at 04:21
  • @JSuar Version 24.0.1312.57. You need to record. Page where you are setting cookie will show that error. Next page will not show that error in webview. – Vivek Goel Feb 13 '13 at 06:51
  • @VivekGoel, btw, according to RFC 6265 http://tools.ietf.org/html/rfc6265#section-4.1.1 you need a space after `Set-Cookie:`. Not that any browsers would complain of course... – Pacerier Jun 07 '13 at 02:15
  • @Pacerier ok. thanks. But this is not problem here. I tried by giving space also. It is reporting same error. – Vivek Goel Jun 07 '13 at 06:37
  • @VivekGoel, I know it's orthogonal to the question. – Pacerier Jun 07 '13 at 06:59

2 Answers2

6

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.

Shrinath
  • 7,888
  • 13
  • 48
  • 85
4

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

Community
  • 1
  • 1
JSuar
  • 21,056
  • 4
  • 39
  • 83
  • It is not fixed. Try this in php - `setcookie('blah', 'blah', time()+100, "/", NULL, false, true);` BTW, I tested on ubuntu 12.04 with same version of chrome you reported in your answer. – Shrinath Feb 14 '13 at 08:22