I want to get cookie to check if my cookie exist or not. But I am not able to do that.
Here the set cookie in my add_cart.php
setcookie(CART_COOKIE,$cart_id,CART_COOKIE_EXPIRE,'/',$domain,false);
//$cart_id is 179, I want to retrieve this cart id
Here is what am I doing:
// Checking Cookie Exist in my init.php file
if (isset($_COOKIE[CART_COOKIE])) {
$cart_id = sanitize($_COOKIE[CART_COOKIE]);
echo "
Cart Id :" . $cart_id; // Here the value showing 0 instead of 179
}
Here is my config.php file
<?php
define('BASEURL', $_SERVER['DOCUMENT_ROOT'] . '/projectdtech/');
define('CART_COOKIE','PhsQ547MJjsmcSJ');
define('CART_COOKIE_EXPIRE',time() + (86400 *30));
?>
I want also check the value of $cart_id in my add_cart.php after reload the page, but after reload it forget the value of $cart_id = 179; It must remember the value of setcoookie($cart_id value). I want to retrieve the value of $cart_id from cookie.
if($cart_id != ''){
}
This is I want to do but have no idea why my code not working. Your suggestions would be welcome. Thank You.