note 90035 added to function.unserialize

From: Date: Thu, 02 Apr 2009 13:49:59 +0000
Subject: note 90035 added to function.unserialize
Groups: php.notes 
Request: Send a blank email to php-notes+get-152763@lists.php.net to get a copy of this message
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"); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 71.172.90.195 ---- Manual Page -- http://www.php.net/manual/en/function.unserialize.php Edit -- https://master.php.net/note/edit/90035 Del: integrated -- https://master.php.net/note/delete/90035/integrated Del: useless -- https://master.php.net/note/delete/90035/useless Del: bad code -- https://master.php.net/note/delete/90035/bad+code Del: spam -- https://master.php.net/note/delete/90035/spam Del: non-english -- https://master.php.net/note/delete/90035/non-english Del: in docs -- https://master.php.net/note/delete/90035/in+docs Del: other reasons-- https://master.php.net/note/delete/90035 Reject -- https://master.php.net/note/reject/90035 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152763) next »