Here is an Online Tool for fixing a corrupted serialized string.
I'd like to add that this mostly happens due to a search and replace done on the DB and the serialization data(specially the key length
) doesn't get updated as per the replace and that causes the "corruption".
Nonetheless, The above tool uses the following logic to fix the serialization data (Copied From Here).
function error_correction_serialise($string){
// at first, check if "fixing" is really needed at all. After that, security checkup.
if ( unserialize($string) !== true && preg_match('/^[aOs]:/', $string) ) {
$string = preg_replace_callback( '/s\:(\d+)\:\"(.*?)\";/s', function($matches){return 's:'.strlen($matches[2]).':"'.$matches[2].'";'; }, $string );
}
return $string;
}