Notice: unserialize() [function.unserialize]: Error at offset (fix)

Started on the old forum in April 2011 · view the original in the archive · old links redirect here

2 replies · 8,054 views · started 15 years ago · 1 min read

3 participants
GumSlone Administrator Principal · 1,690 posts #1

here is a fix for those who get error like: Notice: unserialize() [function.unserialize]: Error at offset while trying to unserialize a serialized string.

fix number 1 (use this function instead of unserialize):

function mb_unserialize($serial_str) { 
$out = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $serial_str ); 
return unserialize($out); 
}

fix number 2 use base64 encoding and decoding of serialized string:

//to safely serialize
$safe_string_to_store = base64_encode(serialize($multidimensional_array));

//to unserialize...
$array_restored_from_db = unserialize(base64_decode($encoded_serialized_string));

both fixes were taken from php.net and from PHP Serialize() & Unserialize Issues

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Lary Softnwords Newbie · 1 posts #3

The solution looks worked perfect for my script. I wonder you have put your thoughts rights to publish it over here

thanks

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close