更新PHP的cookie值 [英] update cookie value in php

查看:141
本文介绍了更新PHP的cookie值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我数组转换成的cookie被PHP序列化功能

I am converting the array into cookie by php serialize function

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

$Promotedcart[] = $PromoteProductArray;

setcookie("Promotedcart", urlencode(serialize($Promotedcart)), time()+604800,'/');

和创建cookie的话时,我使用的反序列化PHP函数。

And when the cookie is created then i am using the unserialize php function.

print_r(unserialize(urldecode($_COOKIE['Promotedcart'])));

我需要更新cookie的值。例如。 - 我需要寻找PromoteProductId值在cookie中退出,如果那么它将更新coorespond到PromoteProductId cookie值。
可以指导我怎么可以更新的价值?

I need to update the cookie value. E.g. - I need to search for PromoteProductId value is exit in the cookie if then it will update the cookie value coorespond to PromoteProductId . could guide me how i can update the value?

推荐答案

您可以简单地将反序列化的cookie存储到一个变量然后重置的cookie?

You can simply store the unserialized cookie into a variable then reset the cookie?

$array = unserialize(urldecode($_COOKIE['Promotedcart']));  
$array[0]["PromoteuserId"] = "New";

setcookie("Promotedcart", urlencode(serialize($array)), time()+604800,'/');

这篇关于更新PHP的cookie值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆