Forum Moderators: coopster
if(!isset($HTTP_COOKIE_VARS['cart_id'])) {
$cart_id = md5(uniqid(rand()));
setcookie("cart_id", $cart_id, time() + 14400);
} else {
$cart_id = $HTTP_COOKIE_VARS['cart_id'];
}
It works fine for me and most users, on both IE6 and Firefox. But for some users, when changing pages or going to the cart, it seems that a new cookie is getting set and resetting the items.
For example, on the red widget page, I add 1 to the cart. Then I visit the blue widget page and find that the cart is empty. I add 2 blue widgets to the cart, which display. Then I go back to the red widget page which displays the 1 red widget that I added before. It should by now be showing 3 items, one red and two blue widgets. When I go to checkout, the cart is empty.
It seems to me that a new cookie should only be set if there isn't one already.
Have you been able to reproduce it consistently?
is it anything to do with switching from http to https?
you could also try setting the domain explicitly, that might be the issue
bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]] )
you are using the first three vars name, value, expire but you could also use path and domain. There are examples on the page I linked to.