01242005 1242 GMT-6
I am passing an array onto another page but I have ran into some problems.
$array = $array();
$array[] = "one";
$array[] = "two";
$array[] = "three";
$var_serial = seralize($array);
$var_value = rawurlencode($var_serial);
input type='text" name="var_value" value=$var_value
On the receiving page:
$var_value = $_POST['var_value'];
$var_strip = stripslashes($var_value);
$var_serial = unserialize($var_strip);
My problem is this. Im echoing out everything before sending it and after receiving it so I can see what is up. When I try to unserialize I get
NOTICE: unserialize() Error at offset 0 of x bytes.
I have tried sending different data through but always get an error.
I did try not doing the rawurlencode() and that did nothing.
Wade
Passing an array in a hidden variable
Moderator: General Moderators
-
wadesmart
- Forum Commoner
- Posts: 38
- Joined: Sat Oct 02, 2004 10:10 pm
- Location: US, Oklahoma
- Contact:
01242005 1258 GMT-6
I didnt make it clear what the problem was. My fault.
I am sending the data just find but when it unserialize() the data is incorrect.
Before:
a:4:{i:0;s:4:"Wade";i:1;s:5:"Kathy";i:2;s:8:"Chandler";i:3;s:5:"Smart";}
After:
a:2:{i:0;s:4:
I dont know why its being cut off after the colen.
Wade
I didnt make it clear what the problem was. My fault.
I am sending the data just find but when it unserialize() the data is incorrect.
Before:
a:4:{i:0;s:4:"Wade";i:1;s:5:"Kathy";i:2;s:8:"Chandler";i:3;s:5:"Smart";}
After:
a:2:{i:0;s:4:
I dont know why its being cut off after the colen.
Wade
-
wadesmart
- Forum Commoner
- Posts: 38
- Joined: Sat Oct 02, 2004 10:10 pm
- Location: US, Oklahoma
- Contact:
No. Im working on a script on my computer.
Here is the actual code though and then a copy of the information from my screen.
page
And the screen contents:
Array
(
[Smart_Family] => a:3:{i:0;s:4:
[Name] => Array
(
[0] => one
[1] => two
[2] => one
)
[Array] => two arrays sent
)
Unserializing.....
Creating array
Populating array = Smart
Serializing array......
The contents of the serialized array...
a:4:{i:0;s:4:"Wade";i:1;s:5:"Kathy";i:2;s:8:"Chandler";i:3;s:5:"Smart";}
Putting data in hidden input.
Here is the actual code though and then a copy of the information from my screen.
page
Code: Select all
<?php
if(isset($_POSTї'Array'])) {
echo "<pre>";
print_r($_POST);
$var_value = $_POSTї'Smart_Family'];
echo "Unserializing.....<br />";
$temp = stripslashes($var_value);
$Smart_Family = unserialize($temp);
foreach($Smart_Family as $member) {
echo "<br />$member";
}
}
?>
<html>
<head>
</head>
<body>
<form method = "post" action = "<?php echo $_SERVERї'PHP_SELF']; ?>" >
<?php
echo "Creating array <br />";
$Smart_Family = array('Wade', 'Kathy', 'Chandler', 'Smart');
echo "Populating array = Smart <br />";
//$Smart_Familyї] = 'Wade';
//$Smart_Familyї] = 'Kathy';
//$Smart_Familyї] = 'Chandler';
echo "Serializing array...... <br />";
$Smart_Family = serialize($Smart_Family);
echo "The contents of the serialized array...<br />";
echo "<br />$Smart_Family <br />";
//echo "<br />Removing any non-required characters....<br />";
//echo "$Smart_Family <br />";
echo "Putting data in hidden input. <br />";
echo "<input type='hidden' name='Smart_Family' value=$Smart_Family>";
?>
Creating second array: Enter three names.
<input type="text" name="Nameї]"><input type="text" name="Nameї]"><input type="text" name="Nameї]">
<input type="submit" name="Array" value="two arrays sent">
</form>
</body>
</html>And the screen contents:
Array
(
[Smart_Family] => a:3:{i:0;s:4:
[Name] => Array
(
[0] => one
[1] => two
[2] => one
)
[Array] => two arrays sent
)
Unserializing.....
Creating array
Populating array = Smart
Serializing array......
The contents of the serialized array...
a:4:{i:0;s:4:"Wade";i:1;s:5:"Kathy";i:2;s:8:"Chandler";i:3;s:5:"Smart";}
Putting data in hidden input.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
the problem is the quote marks that appear in the serialization. You'll need to scrub them out. Then add them back in once you get to the other side.
It may be better to pass this information through sessions..
you may want to try using single quotes around the value you are writing into the html... that might fix it easily
It may be better to pass this information through sessions..
you may want to try using single quotes around the value you are writing into the html... that might fix it easily