Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:23:58+00:00 2026-06-14T12:23:58+00:00

I have an cookie array with json items like this //set my cookie setcookie(my_Cookie,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:23:59+00:00Added an answer on June 14, 2026 at 12:23 pm

    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:

    // Should be the user submitted value to delete.
    // Perhaps a $_GET or $_POST value check.
    $value_to_delete = 9;  
    
    // Should be the cookie value from $_COOKIE['myCookie'] or whatever the name is.
    // Decode from JSON values if needed with json_decode().
    $cookie_items = array( 
        array("item_id" => 9, "item_tag" => "RN"), 
        array("item_id" => 6, "item_tag" => "RN"), 
        array("item_id" => 4, "item_tag" => "RN")
    );
    
    // Run through each item in the cart 
    foreach($cookie_items as $index => $value)
    {
        $key = array_search($value_to_delete, $value);
    
        if($key == "item_id")
        {
            unset($cookie_items[$index]);
        }
    }
    
    // Reset the index
    $cookie_items = array_values($cookie_items);
    
    // Set the cookie
    setcookie($cookie_items);
    
    // Debug to view the set values in the cookie
    print_r($cookie_items);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of data saved in cookie, like this 1:good,2:accelent,3:bad,4:good,fname:Ahmad,lname:Riaz,title:Developer,org:Magiclamp,email:Riaz@khan.com here i
I have the code: $getCookieData = $this->Cookie->read('data'); $getUser = $this->User->find('first', array('conditions' => array('User.username' =>
I have my own asp.net cookie created like this: var authTicket = new FormsAuthenticationTicket(
I have a cookie which stores info in an array. This is for a
I have an array like this: Array ( [utm_source] => website [utm_medium] => fbshare
I have set a cookie in my jsp page say(A). and set its path
How to store large JSON String in cookie ? I have to use cookie
Hello guys I have this code in main.php config file: 'components' => array( '[.........]',
I have a form which is passing a number array like (56,78,98) . I
I have this string being stored in a cookie d967fac49ef2466239168bbbde0a8d755a27ba81$[[\__json_message\\05425\054\This is a message.\]] AKA

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.