Anyone experience of serialize and unserialize

I am trying to pass some serialized data from Flash to PHP and I am having issues on the PHP side. Basically I am getting the serialized data into PHP but cannot unserialize it.

I have therefore created a simple test file to test the unserializing of some serialized data and attempting to display this.

This is my test file code



<?php

	$serializedData = 'a:3:{i:2;a:3:{i:2;i:0;i:1;i:1;i:0;i:0;}i:1;a:3:{i:2;i:0;i:1;i:0;i:0;i:1;}i:0;s:6:\\"lOVELY\\";}';

	echo "serializedData = " . $serializedData;

	$data = unserialize($serializedData); 

	print_r($data); 

	


?>



Basically the print_r statement is displaying nothing

From what I can see you are trying to unserialize


array(
  2,
  array(
   2,0,1,1,0,0
  ),
  1,
  array(2,0,1,0,0,1),
  0,
  "LOVELY"
);

The serialize() of that array is not (as you say):

a:3:{i:2;a:3:{i:2;i:0;i:1;i:1;i:0;i:0;}i:1;a:3:{i:2;i:0;i:1;i:0;i:0;i:1;}i:0;s:6:\“lOVELY\”;}

but is:

a:6:{i:0;i:2;i:1;a:6:{i:0;i:2;i:1;i:0;i:2;i:1;i:3;i:1;i:4;i:0;i:5;i:0;}i:2;i:1;i:3;a:6:{i:0;i:2;i:1;i:0;i:2;i:1;i:3;i:0;i:4;i:0;i:5;i:1;}i:4;i:0;i:5;s:6:“LOVELY”;}

So a:3 is incorrect, should be a:6 (since the arrays have 6 indices, not 3), and you ommitted the indices (it would appear array(0 => 2) serializes to a:1:{i:0;i:2} . Beware that an array ALWAYS has indices, even if you don’t specify them, in which case they start at 0).

Thanks Scallio
It therefore appears that the Flash serialize class has some issues. Eep!
Pau

Actually it seems to be a problem with the flash serialize class dealing with multidimensional arrays containing objects. Back to the drawing board!!!

Couldn’t you create a flash serialize class that works the same way the PHP version does?

To me it seems the PHP version is not that complicated.

I’m not sure where ScallioXTX got the idea that it should be that array (he may be correct, but I don’t think so).

If you simply remove the backslashses before the double quotes in the original serialized string, the resultant array is:

Array
(
    [2] => Array
        (
            [2] => 0
            [1] => 1
            [0] => 0
        )

    [1] => Array
        (
            [2] => 0
            [1] => 0
            [0] => 1
        )

    [0] => lOVELY
)

The snippet would be:

$serializedData = 'a:3:{i:2;a:3:{i:2;i:0;i:1;i:1;i:0;i:0;}i:1;a:3:{i:2;i:0;i:1;i:0;i:0;i:1;}i:0;s:6:"lOVELY";}';
echo "serializedData = " . $serializedData . PHP_EOL;
$data = unserialize($serializedData);
print_r($data);

Salathe, you’re completely right.
I stand corrected, it could be your array as well :slight_smile: