0
我想在一个cookie中存储一个json字符串,但是,特殊字符,如; {"":""}
得到编码。我试过setrawcookie()
,但它不存储多个属性值。如何在PHP中使用PHP存储原始json字符串?
$array = array('test' => 'value', 'anothertest' => 'not stored');
setrawcookie($this->cookie_customs_name, stripslashes(json_encode($array)),
strtotime($this->cookie_life_time), $this->cookie_path, $this->cookie_domain);
我在这里做错了什么?
另外,是否有可能使用setcookie()
方法实现此目的?
那么,什么问题?被编码的字符有什么问题?当你需要阅读它时,你不能解码吗? –
您应该在设置时删除您的stripslashes()调用。你需要逃避那些角色。只需在检索cookie时将其删除。 – Chris
json上的stripslashes()可能会破坏json字符串。不要这样做。 –