unserialize():13个字节的偏移9处的错误

时间:2017-06-11 08:39:28

标签: php arrays

我收到此错误?这是什么意思?

 unserialize(): Error at offset 9 of 13 bytes

这是我在数组中序列化并存储数组后得到的结果:

a:3:{i:0;s:6:

在反序列化时,它会出错!我该怎么办? 我想要我的原始阵列,并希望显示它。

我尝试过其他帖子,比如basencoder / decode,但那也不行..

Create1.php(通过隐藏输入将序列化数组传递到下一页)

<form action="create2.php" method="POST">
<table cellpadding="10">
<tr>
  <td>Name</td>
  <td><input type="text" name="name" value="<?php echo $name; ?>" readonly="readonly" ></td>
</tr>
<tr>
  <td>Mobile</td>
  <td><input type="text" name="mobile" value="<?php echo $mobile; ?>" readonly="readonly" /></td>
</tr>
<tr>
  <td>Email</td>
  <td><input type="text" name="email" value="<?php echo $email; ?>" readonly="readonly" /></td>
</tr>
<tr>
  <td>Company</td>
  <td><input type="text" name="company" value="<?php echo $company; ?>" readonly="readonly" /></td>
</tr>
<tr>
  <input type="hidden" name="original_list" value="<?php echo serialize($original_list); ?>"  />
  <input type="hidden" name="xerox_list" value="<?php echo serialize($xerox_list); ?>" />
</tr>
<tr>
  <td><input type="submit" value="Confirm" /></td>
</tr>
</table>
</form>

Create2.php(在数据库中获取并存储序列化数组)

$name = $_POST['name'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$company = $_POST['company'];
$original = $_POST['original_list'];
$xerox = $_POST['xerox_list'];


echo $sql = "INSERT INTO users (name,mobile,email,company,original,xerox)
VALUES ('$name','$mobile','$email','$company','$original','$xerox')";
mysqli_query($con,$sql);

1 个答案:

答案 0 :(得分:1)

我不确定在HTML中使用二进制字符串是否安全(毕竟HTTP是一种文本协议)。我建议使用JSON编码而不是序列化。

<input type="hidden" name="original_list" value="<?php echo json_encode($original_list); ?>"  />
 <input type="hidden" name="xerox_list" value="<?php echo json_encode($xerox_list); ?>" />

访问条目时,您可以执行以下操作:

json_decode($row['original'],true); //you get the idea