Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

arrays - update cookie value in 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,'/');

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

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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,'/');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...