Home > PHP 5.0 > PHP unserialize(): Error at offset – Error Solution

PHP unserialize(): Error at offset – Error Solution


Some time when we unserialize a variable in PHP, an error come out like

unserialize(): Error at offset

The reason of this error is corruption in “, ‘, :, & ; characters.

Quick Solution

the solution is 2 step based.

  1. While serializing the variable encode it with base64 encoding.

    base64_encode(serialize($data))

  2. While unserializing the variable decode the serialized variable using base64 encoding.

    unserialize(base64_decode($data))

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: