天天看点

php对象序列化和cookie的问题,反序列化false

php对象序列化和cookie的问题,反序列化false

$searchKeywords = array("羊奶","肥皂");
        $searchKeywords = serialize($searchKeywords);//序列化
        echo $searchKeywords;
        setcookie("searchKeywords",$searchKeywords, time()+3600*24);
        var_dump($_COOKIE['searchKeywords']);//查看存入的值
        var_dump(unserialize($_COOKIE['searchKeywords']));//反序列化      

看结果:

php对象序列化和cookie的问题,反序列化false

由图得知:

$KeywordsStr = $_COOKIE['searchKeywords'];
        $KeywordsStr= str_replace('\"', '"', $KeywordsStr);      

继续阅读