我正在尝试将json字符串存储在cookie中,但是,特殊字符,如;{"":""}会被编码。
我尝试过setrawcookie(),但它不能存储超过一个属性值。
$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()方法来实现这一点?
发布于 2015-09-14 22:55:08
使用setcookie()时,应自动对特殊字符进行转义。检索cookie后,只需删除斜杠即可。
$array = array(....);
setcookie($this->cookie_customs_name, json_encode($array), ...);检索cookie时:
$cookie = stripslashes($_COOKIE[$this->cookie_customs_name]);
$cookie = json_decode($cookie);未经测试,但应该是所需的全部内容。
https://stackoverflow.com/questions/32567709
复制相似问题