【发布时间】:2011-11-16 19:25:29
【问题描述】:
我正在通过 php 序列化函数将数组转换为 cookie
$PromoteProductArray = array("PromoteuserId"=>$PromoteuserId,
"PromoteProductId"=>$PromoteProductId,
"PromoteBrandId"=>$PromoteBrandId);
$Promotedcart[] = $PromoteProductArray;
setcookie("Promotedcart", serialize($Promotedcart), time()+604800,'/');
当创建 cookie 时,我正在使用反序列化 php 函数。
print_r(unserialize($_COOKIE['Promotedcart']));
它不起作用。
当我print_R($_COOKIE) 时,它会告诉我价值。
【问题讨论】:
-
测试数据很有帮助,你能不能贴出样本
-
See this StackOverflow question 以获得更好的答案。
-
请不要在用户提交的数据上使用
unserialize。这很容易通过使用 PHP 的 __wakeup 和 __destruct 方法的对象注入来利用。您可以使用json_encode/json_decode代替serialize/unserialize。 owasp.org/index.php/PHP_Object_Injection
标签: php arrays serialization cookies