开发者

Remove from cookies problem

Here is how i am adding the item to a cookie.

addtobasket.php

<?php
include(dirname(__FILE__)."/../config.php");

$product = $_GET['p'];

setcookie("products[$product]", $product,time()+3600,'/','domainehre.com');


echo "$product added to basket";
//Show current basket products


?>

It adds to cookies all great and i can view the cookie all good.

but its not removing with this code:

remove.php

<?php
include(dirname(__FILE__)."/../config.php");

$product = $_GET['remove'];

if (isset($_COOKIE["products"])) {
  //Remove product/s from basket
    setcookie("products[$product]", "", time()-3600);
    echo "Removed $produ开发者_运维技巧ct from basket, <br /> <a href='basket.php'>Click here to go back to basket</a>";
}else{
    echo "Basket is empty";
}
?>

What do you guys think it is ?

Thanks


Remove the cookie using the same domain and path it was set with:

setcookie("products[$product]", "", time()-3600);

// Should be
setcookie("products[$product]", "", time()-3600, '/', 'domainhere.com');


I'm assuming that the name of the GET parameter is "products". To remove the cookie you have to do this:

setcookie("products", "", time()-3600);

The w3c school has a great example:

http://www.w3schools.com/php/php_cookies.asp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜