小编Ami*_*mit的帖子

更新 php 中的 cookie 值

我通过 php 序列化函数将数组转换为 cookie

$PromoteuserId='1';
$PromoteProductId='2';
$PromoteBrandId='3';
$PromoteProductArray = array("PromoteuserId"=>$PromoteuserId,
                            "PromoteProductId"=>$PromoteProductId,
                              "PromoteBrandId"=>$PromoteBrandId
                        );

$Promotedcart[] = $PromoteProductArray;

setcookie("Promotedcart", urlencode(serialize($Promotedcart)), time()+604800,'/');
Run Code Online (Sandbox Code Playgroud)

创建 cookie 后,我将使用反序列化 php 函数。

print_r(unserialize(urldecode($_COOKIE['Promotedcart'])));
Run Code Online (Sandbox Code Playgroud)

我需要更新 cookie 值。例如 - 我需要在 cookie 中搜索 PromotionProductId 值,如果那么它会将 cookie 值更新为与 PromotionProductId 一致。可以指导我如何更新该值吗?

php arrays cookies store setcookie

2
推荐指数
1
解决办法
7741
查看次数

标签 统计

arrays ×1

cookies ×1

php ×1

setcookie ×1

store ×1