dongnachuang6635 2011-09-21 17:14
浏览 49

跨浏览器Cookie过期不一致

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 widely 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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求帮我调试一下freefem代码
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图