繁体   English   中英

从PHP读取时,更改Cookie信息

[英]Change in Cookie information, when read from PHP

我的问题是这个。 我正在使用包含值的Java脚本设置Cookie

"MXGWJfgr4HDINl/BdAfBUf12710aFNcaIQKgGJ7VShxvprVo1XK+Hntg"  

现在,当我在PHP页面上接收并读取此cookie时,我将内容获取为

"MXGWJfgr4HDINl/BdAfBUf12710aFNcaIQKgGJ7VShxvprVo1XK Hntg"

“ +”号变为空格字符。 为什么会这样呢?

根据document.cookie参考:

Cookie值字符串可以使用encodeURIComponent()来确保该字符串不包含任何逗号,分号或空格(cookie值中不允许使用这些空格)。

因此,这是您需要做的:

document.cookie = "foobar=" + encodeURIComponent("MXGWJfgr4HDINl/BdAfBUf12710aFNcaIQKgGJ7VShxvprVo1XK+Hntg");
alert(document.cookie); // + becomes %2B which PHP will interpret and decode automatically

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM