I have a task which is compare up to five products from the product list. For that I have followed following steps:
step 1:
set onclick event when we click add to compare button of each product. In this event I have set cookie by javascript using this code.
// cookie is set by array because of we have to store 1 to 5 products
var comparearray = [productid];
document.cookie = "compareitem" + "=" + comparearray;
It is successfully set the cookie value which holds product id of those are selected to compare.
Step 2: In my PHP file I have tried to retrieve this cookie value.BY,
$cookie_val = $_COOKIE['compareitem '];
But it is not worked. I don't know this kind of concept is worth. If know, give me the instructions how to solve my problem. Thanks in advance.