序列化和发布但无法反序列化

时间:2014-10-12 16:54:32

标签: php

序列化并发布但无法反序列化

这是在数组上使用序列化后的输入数据

<input type='hidden' name='play_data' value='a:2:{i:0;a:7:{s:7:"play_day";s:1:"6";s:10:"play_number";s:4:"1872";s:7:"play_big";s:1:"1";s:9:"play_small";s:1:"1";s:8:"play_user";s:2:"b1";s:8:"play_page";s:3:"001";s:8:"play_roll";s:1:"Y";}i:1;a:7:{s:7:"play_day";s:1:"6";s:10:"play_number";s:4:"1873";s:7:"play_big";s:1:"2";s:9:"play_small";s:1:"0";s:8:"play_user";s:2:"b1";s:8:"play_page";s:3:"001";s:8:"play_roll";s:1:"Y";}}'>

当我发布时

$play_data = mysql_real_escape_string($_POST['play_data']);
echo $play_data;

它给我输出

a:2:{i:0;a:7:{s:7:\\\"play_day\\\";s:1:\\\"6\\\";s:10:\\\"play_number\\\";s:4:\\\"1872\\\";s:7:\\\"play_big\\\";s:1:\\\"1\\\";s:9:\\\"play_small\\\";s:1:\\\"1\\\";s:8:\\\"play_user\\\";s:2:\\\"b1\\\";s:8:\\\"play_page\\\";s:3:\\\"001\\\";s:8:\\\"play_roll\\\";s:1:\\\"Y\\\";}i:1;a:7:{s:7:\\\"play_day\\\";s:1:\\\"6\\\";s:10:\\\"play_number\\\";s:4:\\\"1873\\\";s:7:\\\"play_big\\\";s:1:\\\"2\\\";s:9:\\\"play_small\\\";s:1:\\\"0\\\";s:8:\\\"play_user\\\";s:2:\\\"b1\\\";s:8:\\\"play_page\\\";s:3:\\\"001\\\";s:8:\\\"play_roll\\\";s:1:\\\"Y\\\";}}

$play_data = unserialize($play_data);
echo $play_data;

它没有为此返回任何内容

如何在帖子序列化之前检索我的数组。

序列化并发布但无法反序列化

这是在数组上使用序列化后的输入数据

<input type='hidden' name='play_data' value='a:2:{i:0;a:7:{s:7:"play_day";s:1:"6";s:10:"play_number";s:4:"1872";s:7:"play_big";s:1:"1";s:9:"play_small";s:1:"1";s:8:"play_user";s:2:"b1";s:8:"play_page";s:3:"001";s:8:"play_roll";s:1:"Y";}i:1;a:7:{s:7:"play_day";s:1:"6";s:10:"play_number";s:4:"1873";s:7:"play_big";s:1:"2";s:9:"play_small";s:1:"0";s:8:"play_user";s:2:"b1";s:8:"play_page";s:3:"001";s:8:"play_roll";s:1:"Y";}}'>

当我发布时

$play_data = mysql_real_escape_string($_POST['play_data']);
echo $play_data;

它给我输出

a:2:{i:0;a:7:{s:7:\\\"play_day\\\";s:1:\\\"6\\\";s:10:\\\"play_number\\\";s:4:\\\"1872\\\";s:7:\\\"play_big\\\";s:1:\\\"1\\\";s:9:\\\"play_small\\\";s:1:\\\"1\\\";s:8:\\\"play_user\\\";s:2:\\\"b1\\\";s:8:\\\"play_page\\\";s:3:\\\"001\\\";s:8:\\\"play_roll\\\";s:1:\\\"Y\\\";}i:1;a:7:{s:7:\\\"play_day\\\";s:1:\\\"6\\\";s:10:\\\"play_number\\\";s:4:\\\"1873\\\";s:7:\\\"play_big\\\";s:1:\\\"2\\\";s:9:\\\"play_small\\\";s:1:\\\"0\\\";s:8:\\\"play_user\\\";s:2:\\\"b1\\\";s:8:\\\"play_page\\\";s:3:\\\"001\\\";s:8:\\\"play_roll\\\";s:1:\\\"Y\\\";}}

$play_data = unserialize($play_data);
echo $play_data;

它没有为此返回任何内容

如何在帖子序列化之前检索我的数组。

更新:

对于那些建议我带走mysql_escape_string的人。

这是php代码

$play_data = $_POST['play_data'];

echo "Play Data without Unserialize<br/>" . $bet_data;


$play_data = unserialize($play_data);

echo "Play Data with Unserialize<br/>" . $bet_data

这是输出

Play Data without Unserialize
a:2:{i:0;a:7:{s:7:\"play_day\";s:1:\"6\";s:10:\"play_number\";s:4:\"1872\";s:7:\"play_big\";s:1:\"1\";s:9:\"play_small\";s:1:\"1\";s:8:\"play_user\";s:2:\"b1\";s:8:\"play_page\";s:3:\"001\";s:8:\"play_roll\";s:1:\"Y\";}i:1;a:7:{s:7:\"play_day\";s:1:\"6\";s:10:\"play_number\";s:4:\"1873\";s:7:\"play_big\";s:1:\"2\";s:9:\"play_small\";s:1:\"0\";s:8:\"play_user\";s:2:\"b1\";s:8:\"play_page\";s:3:\"001\";s:8:\"play_roll\";s:1:\"Y\";}}

PLay Data with Unserialize

1 个答案:

答案 0 :(得分:0)

首先,在反序列化之前,不要添加斜杠。

接下来你不能回显一个数组。你必须使用print_r()。

所以只需使用:

print_r(unserialize($_POST['play_data']));

编辑: 因为它仍然添加斜杠,试试这个:

print_r(unserialize(stripslashes($_POST['play_data'])));