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

    报告相同问题?

    悬赏问题

    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)