Created
August 5, 2019 08:12
-
-
Save D4R4/e322ab5d8bd1013175108bc1acfe32e8 to your computer and use it in GitHub Desktop.
PHP corrupted serialized string fixer, usefull for Wordpress options data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function serialize_corrector($serialized_string){ | |
// at first, check if "fixing" is really needed at all. After that, security checkup. | |
if ( @unserialize($serialized_string) !== true && preg_match('/^[aOs]:/', $serialized_string) ) { | |
$serialized_string = preg_replace_callback( '/s\:(\d+)\:\"(.*?)\";/s', function($matches){return 's:'.strlen($matches[2]).':"'.$matches[2].'";'; }, $serialized_string ); | |
} | |
return $serialized_string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment