Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unserialize Error at offset 5 of 9 bytes

I'm trying to pass an array trough a html-form input field. Using serialize to pass it and then unserialize to read the array again. I have multiple input fields.

$test = array('name' => 'Sander', 'type' => 'melon');

echo '<input type="hidden" name="rank[]" value="'.serialize($test).'" >';

Then If I want to unserialize it and show the data it gives an error:

$list = $_POST['rank'];
var_dump($list);
var_dump(unserialize($list[0]));

enter image description here

like image 455
Sharpless512 Avatar asked Apr 26 '13 10:04

Sharpless512


2 Answers

You most likely need to pass the serialized string through urlencode() before outputting.

To process it then, use urldecode() before unserialize().

like image 59
Nick Andriopoulos Avatar answered Oct 13 '22 01:10

Nick Andriopoulos


try

 $list = urldecode($_GET['rank']);
//var_dump($list);
var_dump(unserialize($list));
$test = array('name' => 'Sander', 'type' => 'melon');?>
<form >
<input type='hidden' name='rank' value='<?php echo serialize($test);?>' >
<input type="submit" >
</form>
like image 34
Rakesh Sharma Avatar answered Oct 13 '22 02:10

Rakesh Sharma