I have an cookie array with json items like this
//set my cookie
setcookie("my_Cookie", $cookie_content, time()+3600);
//this is the content of my cookie for example with 2 items
[{"item_id":"9","item_tag":"AS","session_id":"554obe5dogsbm6l4o9rmfif4o5"},{"item_id":"6","item_tag":"TE","session_id":"554obe5dogsbm6l4o9rmfif4o5"}]
The workflow is like an shopping cart, I can add and delete items. One “product” on my website contains: item_id, item_tag and the session_id;
For adding an item the cookie will be extended with item_id”:”X”,”item_tag”:”X”,”session_id”:”X
now if I click on delete I want remove the current three values in the cookie
I try it with
unset($_COOKIE[“my_Cookie”, ‘item_id’=> $item_id, ‘item_tag’=> $item_tag, ‘session_id’=> $session_id]); but this doesn’t work
Is it possible to delete specific values of my cookie?
If I’m not mistaken, you can’t directly modify a cookie’s value; you’ll have to read the value, make any modifications, and then replace the cookie using the same name.
So, in this case, once a user hits the delete link, your script should save the ID of the item that they want removed, read the cookie value(s), rewrite the array and then replace the cookie with the updated values.
Perhaps this demo will help: