且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Cookie 设置两次;如何删除重复项?

更新时间:2023-02-05 20:05:50

Dude(tte),您的 cookie setter 中存在不一致和错误.

Dude(tte), there are inconsistencies, and a bug, in your cookie setter.

清除cookie和设置cookie的路径和域应该相同.在此处查看您的代码:

The path and domain should be the same for both clearing the cookie and setting it. See your code here:

document.cookie = c_name + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";

并将其与:

var c_value=escape(value) + "; expires=" + exdate.toUTCString(); + "; path=/spring; domain=aroth.no-ip.org";

你会看到 setter 有两个,但 deleter 没有.你会带来混乱.

you will see that the setter has both of them, but the deleter doesn't. You will bring about chaos.

我上面引用的第二行代码,在字符串连接表达式中间引入了一个分号.紧接在 exdate.toUTCString() 之后.杀死它.杀了它……现在.

That second line of code I quoted above, has a semicolon introduced in the middle of a string concatenation expression. Right after exdate.toUTCString(). Kill it. Kill it…now.

至少在我的谷歌浏览器上,我设法让它正确运行,如果我在 json = "[" + json + "]"; 设置断点并修改 setCookie 在它被执行之前.

At least on my Google Chrome, I managed to get it run correctly, if I set a breakpoint at json = "[" + json + "]"; and modify setCookie before it is executed.

P/S:这是一次奇怪的调试体验,我设法设置了 4 个 layoutState cookie,通过摆弄路径 &域.

P/S: It was a bizzare debugging experience, where I managed to set 4 layoutState cookies, by fiddling with path & domain.