search

Home  >  Q&A  >  body text

php - Deserialization error, background data becomes suspiciously garbled?

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_u1582phpcn_u15822806 days ago881

reply all(4)I'll reply

  • PHPz

    PHPz2017-05-16 13:10:00

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

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 13:10:00

    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

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:10:00

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

    That data is base64 encoded, not garbled.

    reply
    0
  • 怪我咯

    怪我咯2017-05-16 13:10:00

    unserialize(base64_decode($str))

    reply
    0
  • Cancelreply