php - Deserialization error, background data becomes suspiciously garbled?
phpcn_u1582
phpcn_u1582 2017-05-16 13:08:00
0
4
852

Use serialize() to serialize the data and insert it into the database, and then use unserialize() to deserialize it and encounter some data string errors;
The error content is:unserialize() [function.unserialize ]: Error at offset 0 of 2544 bytes

I searched many solutions on Google and they all said that the problem was caused by encoding problems
So the place where I inserted it was changed to base64_encode(serialize($str));
The place where I read it was changed to
unserialize(preg_replace('!s:(d+):"(.*?)";!se', '"s:".strlen("$2").":"$2";"', $string))

I tried it and it worked but it was not completely resolved. Later, the same error occurred in some datagrams. Looking at the background data, I found that the inserted content turned into something similar to the garbled code below

< /p>

Please help me find out the reason, preferably in more detail.

phpcn_u1582
phpcn_u1582

reply all(4)
PHPzhong

Post some source data, otherwise how can you test it? .

洪涛

Confirm whether there is any problem with your serialized data. I used serialize before, but it always had problems. Then I had no choice but to change to json_decode

曾经蜡笔没有小新

base64_encode("a:1") == "YTox".

That data is base64 encoded, not garbled.

刘奇
unserialize(base64_decode($str))
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template