3

So I have a line in php that sets a cookie and it has been working for a while now, but, this week chrome does not want to keep the cookie. The cookie gets added and when I hit refresh in the chrome dev tools it disappears.

Chrome for both Windows and OS X are doing the same thing. Chrome started doing this out of the blue. Firefox on Windows and OS X and safari on OS X do not have the issue.

I am using a date far enough in advance that its not an expiry issue.

Does anyone have any experience with this?

Currently running:

setcookie('key', $value, time()+3600, '/');

Was running:

setcookie('key', $value, 2000000000, '/');
Joel
  • 43
  • 3

2 Answers2

1

based on documentation expire in Unix timestamp check this link

https://en.wikipedia.org/wiki/Year_2038_problem

best, set expire 0 or calculate no more of year 2038

setcookie("keyCookie", $value, 0);
kiamnemr
  • 124
  • 10
  • This did not fix the issue. First off the cookie now shows that it expires session which is not the desired effect. The cookie needs to stay in place and secondly, when I refresh the dev tools the cookie immediately disappears. – Joel Jan 03 '14 at 16:03
0

It seems like I may have solved the issue of the cookie disappearing. I'm not sure it's a real fix but at least it is not disappearing now.

Here is how the code looks:

setcookie('key', $value, 2000000000, '/', 'www.site.com');

Now the only difference between the two cookies in the dev tools is a preceding period in the domain path. I don't know why this would be causing a problem for Chrome.

Not Persistant:

key | value | www.site.com | / | Wed, 18 May 2033 03:33:19 GMT | 100

Persistant:

key | value | .www.site.com | / | Wed, 18 May 2033 03:33:19 GMT | 100
Joel
  • 43
  • 3