I currently store a list of table primary keys in a cookie for users that are not logged in. I can add to it with not problem but when I try to delete, under certain situation multiple values are being deleted.
An example, if the cookie stores the value "-1-2-3-4-5-6" and I delete "6" so the value is "-1-2-3-4-5-" then I delete "5", "1" will also be deleted.
My code for deleting is below
$value = isset(Yii::app()->request->cookies['wrap_crcpd_wishlist']) ? Yii::app()->request->cookies['wrap_crcpd_wishlist']->value : '';
if($value != ''){
$value = str_replace($id, '', $value);
$value = str_replace('--', '-', $value);
Yii::app()->request->cookies['wrap_crcpd_wishlist'] = new CHttpCookie('wrap_crcpd_wishlist', $value);
echo "wishlist = {'id':'".$id."', 'message':'product deleted from wishlist', 'count':'".Yii::app()->wishlistChcker->wishlistNumber()."'}";
}
How can I stop this from happening?
Thank you