我的网站有时需要使用php读取javascript cookie,但有时候我会从像#16 3CFJ这样的用户那里得到奇怪的字符集,而对于某些用户来说,它会正确地读取它。因此,我认为问题出在客户端。我用这种方法写cookie:
var expireDate = new Date();
expireDate.setMonth(expireDate.getMonth() + 1);
var value="Sami";
document.cookie = "name="+value+";path=/;expires="+expireDate.toGMTString();
和$_COOKIE['name']
使用php读取它。
答案 0 :(得分:1)
Cookie无法使用标头处理。所以,
使用base64_encode()
对您的Cookie进行编码,然后使用base64_decode()
进行解码,以便对其进行解读。
要在Javascript中进行编码/解码,this答案可能有所帮助。