I've done
<?php
echo "initial values in the cart: <pre>";print_r($_COOKIE);echo "</pre>";
$_COOKIE['cart']=null;
setcookie("cart", "", time()-3600);
unset($_COOKIE['cart']);
unset($_COOKIE);
?>
<script>
alert( "before delete " +$.cookie("cart") );
</script>
<script>
$.cookie("cart")="";
$.cookie('cart', null);
$.cookie('cart',null,{path:'/');
$.cookie("cart")=null;
$.cookie('cart', '', { expires: -150 });
jQuery.cookie("cart", '',{expires: -1,path:'/'});
$.cookie("cart")=undefined;
delete $.cookie("cart");
$.cookie("cart","",);
$.removeCookie('cart', { path: '/' });
$.removeCookie("cart");
alert( "just delete " +$.cookie("cart") );
</script>
<script>
if($.cookie('cart') === null || $.cookie('cart') === "")
{
alert( " cookie deleted 1 " +$.cookie("cart") );
}
else
{
//have cookie
alert( "have cookie " +$.cookie("cart") );
}
if (typeof $.cookie('cart') === 'undefined'){
//no cookie
alert( " cookie deleted 2 " +$.cookie("cart") );
}
// if($.cookie('cart') === null || $.cookie('cart') === ""
// || $.(cookie('cart') === "null" || $.cookie('cart') === undefined))
// {
// alert( " cart cookie deleted 3 " +$.cookie("cart") );
// }
</script>
<script>
alert( "after delete " + $.cookie("cart") );
</script>
<?php
echo "Items after cookie in the cart is unset: <pre>";print_r($_COOKIE);echo "</pre>";
?>
output is:
(1) it prints the initial values in the cart, cookie has cart variable set
(2) before delete alert
(3) have cookie alert
(4) after delete alert
(5) print_r
throwing notice Undefined variable: _COOKIE
Insights:
--> primarily am setting cookie through jquery and am able to access it by output (1)
--> next i unset
cookie print_r
throwing says Undefined variable
and with through alerts am still able to see the cookie value, I tried to delete the cookie in the jquery way yet in all alerts cookie value is shown, in the end again print_r($_COOKIE)
says Undefined variable
--> i wish on page refresh output (1) i.e., print_($_COOKIE['cart'])
has to say Undefined variable cart
but still returning original/old cookie-cart variable.
please suggest me how to unset the cookie properly
with mozilla's cookie add-on i found path of cookie is correct as mentioned above
solved
leaving jquery aside i tried setcookie('cart', null, -1, '/');
and it has solved my issue!
Thanks!