Click to See Complete Forum and Search --> : Problem passing arrays between pages using serialize method


clem_c_rock
12-13-2005, 01:50 PM
Hello,

I'm trying to serialize an array, then throw it into a url stream to pass it to a new page where I will then unserialize the array. When I pass it to the next page and do a print_r( $unserialized_array ), I get no values.

Here's the code I'm trying:

Page 1:

$array = array();
$array["a"] = "Foo";
$array["b"] = "Bar";
$array["c"] = "Baz";
$array["d"] = "Wom";

$test_array = serialize( $array );

Url string: <a href="page_2.php?serialized_array=<?=$test_array ?>" >


Page 2:

$this_code_array = array();
$this_code_array = unserialize( urldecode( $_REQUEST['serialized_array'] ) );
print_r( $this_code_array ); // will not print anything

devinemke
12-13-2005, 03:13 PM
<?php
if (!isset($_GET['array']))
{
$array = array(
'a' => 'Foo',
'b' => 'Bar',
'c' => 'Baz',
'd' => 'Wom'
);

echo '<a href="' . $_SERVER['PHP_SELF'] . '?array=' . urlencode(serialize($array)) . '">array link</a>';
}
else
{
print_r(unserialize(urldecode(stripslashes($_GET['array']))));
}
?>

clem_c_rock
12-13-2005, 07:57 PM
Thanks - that was the ticket!

Appreciate all the help!