开发者

Cross Browser Cookie Expiration Inconsistencies

I'm looking for a way to set cookies with a short duration against all browsers. Apparently each browser handles the PHP setcookie method differently. Below are my results.

The PHP code:

setcookie("TestCookie", $value, time()+7200, "/", ".domain.com", 1, true);

The Results:

OPERA 11.10

Local time of test: 1316621628
PHP Server Time: Wed Sep 21 07:58:35 PDT 2011
Cookie Expiration Time: 2011-09-21 - 20:58:35

Chrome 6.0.472.63

Local time of test - 1316621761
PHP Server Time - Wed Sep 21 08:01:21 PDT 2011
Cookie Expiration Time - Wednesday, September 21, 2011 9:01:21 PM

Firefox 4

Local time of test: 1316622064
PHP Server Time: Wed Sep 21 08:07:38 PDT 2011
CookieExpiration Time: Wednesday, September 21, 2011 10:22:50 PM

Safari 3.2.3

Local time of test: 1316622359
PHP Server Time: Wed Sep 21 08:10:48 PDT 2011
CookieExpiration Time: 9/21/11 5:10 PM

Internet Explorer 8

Local time of test: 1316623009
PHP Server Time: Wed Sep 21 08:21:37 PDT 2011

Cookie Data: 
TestCookie
x
domain.com/
9728
3932016640
30177410
2837190416
30177404

As you can see, the expiration date/time for the cookies varies wide开发者_Python百科ly from working as intended to being several hours in the past to only being 1 hour! Very frustrating.

In addition to trying the above method, I've also tried setting the exact expiration date/time via unixtime... I've done this with both time() at the PHP level, or utilizing the browser's unixtime retrieved through JavaScript.

setcookie("TestCookie", $value, 1316621928, "/", ".domain.com", 1, true);

Each browser handles this differently as well. I can't seem to find one method that works the same for all browsers. Is anyone aware of a method that accomplishes this?

Thank you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜