Depending on how you have organized the data structures in which the basket is stored. For example, you store a basket in cookies in json type:
[{"id":идентификатор_товара,"count":количество},{...}]
then a php handler that accepts a get-parameter product identifier will be like (add and delete in one, I think you will figure it out):
<?php // add to cart $item_id = $_GET['id']; if(isset($_COOKIE['cart'])) $cart = json_decode($_COOKIE['cart']); else $cart = array(); $is_in_cart = false; foreach($cart as $key=>$value) { if($value->id == $item_id) { $cart[$key]->count++; $is_in_cart = true; }//if($value->id == $item_id) }//foreach($cart as $key=>$value) if(!$is_in_cart) { $cart[] = array('id'=>$item_id,'count'=>1); }//if(!$is_in_cart) setcookie("cart", json_encode($cart), time() + (86400 * 30), "/"); print_r(json_decode($_COOKIE['cart'])); exit; //delete from cart $item_id = $_GET['id']; foreach($cart as $key=>$value) { if($value->id == $item_id) { $count = $cart[$key]->count; if($count == 1) unset($cart[$key]); else $cart[$key]->count--; }//if($value->id == $item_id) }//foreach($cart as $key=>$value) print_r(json_decode($_COOKIE['cart'])); exit;