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字符串。不要這樣做。 –