[英]Change in Cookie information, when read from PHP
My problem is this. 我的问题是这个。 I'm setting a cookie using java script, which contains value 我正在使用包含值的Java脚本设置Cookie
"MXGWJfgr4HDINl/BdAfBUf12710aFNcaIQKgGJ7VShxvprVo1XK+Hntg"
Now, when i receive and read this cookie on a PHP page, im getting the content as 现在,当我在PHP页面上接收并读取此cookie时,我将内容获取为
"MXGWJfgr4HDINl/BdAfBUf12710aFNcaIQKgGJ7VShxvprVo1XK Hntg"
The '+' sign is change to a space character. “ +”号变为空格字符。 Why is it so? 为什么会这样呢?
According to document.cookie reference: 根据document.cookie参考:
The cookie value string can use encodeURIComponent() to ensure that the string does not contain any commas, semicolons, or whitespace (which are disallowed in cookie values). Cookie值字符串可以使用encodeURIComponent()来确保该字符串不包含任何逗号,分号或空格(cookie值中不允许使用这些空格)。
So this is what you need to do: 因此,这是您需要做的:
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.