簡體   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