note 90035 deleted from function.unserialize by aharvey

From: Date: Tue, 06 Nov 2012 01:36:58 +0000
Subject: note 90035 deleted from function.unserialize by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191724@lists.php.net to get a copy of this message
Note Submitter: Gary ---- Removing __PHP_Incomplete_Class Object this code will remove the __PHP_Incomplete_Class Object error when trying to pull data from a text sql file you dont know the class name of. i am simply using the data to generate a report i have looked for something like this so hopefully this example will help someone the basic php to call the function is $session_data = base64_decode($YOURSERIALIZEDDATA); $decodedtext=unserializeUnknownObject($session_data); if base64 encoded or $decodedtext=unserializeUnknownObject($YOURSERIALIZEDDATA); if simply serialized include_once 'include\phperrorclass.php'; <?php class MyClass {} $object = unserialize($serializedData); ?> include_once 'include\phperrorfunction.php'; <?php function unserializeUnknownObject($text) { $matches = Array(); preg_match_all('/O:(\d)*:"([^":]*)":/', $text, $matches); foreach ($matches[2] as $class) { if (!class_exists($class, False)) { eval('class '.$class.' { }'); } } return unserialize($text); } $object = unserializeUnknownObject($serializedData); ?> sample code <?php //declare the unknown object include_once 'include\phperrorclass.php'; include_once 'include\phperrorfunction.php'; //declare the unserialize function $abs_path = dirname(dirname(__FILE__)); include $abs_path.'\sunshop_reports\include\config.php'; // Connects to your Database $connection=mysql_connect($servername, $dbusername, $dbpassword) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $sql_query=" SELECT * FROM ss_orders_products LIMIT 0 , 30"; $result=mysql_query($sql_query,$connection); if (!$result) { die('Invalid query: ' . mysql_error()); } $session_data = array(); while($row=mysql_fetch_array($result)) { $return[] = $row; echo(" OrderID - "); print_r($row[1]); echo(" Data Array - "); $pulledata=($row[4]); $session_data = base64_decode($row[4]); $decodedtext=unserializeUnknownObject($session_data); echo nl2br("\n"); print_r($decodedtext); echo nl2br("\n"); echo nl2br("\n"); } ?>

« previous php.notes (#191724) next »