Answer the question
In order to leave comments, you need to log in
Why can't connected pages see cookies?
Hello! I installed the CNC and ran into this problem: all pages that connect to index.php do not see the cookies that were created when the page was first opened. The idea is that cookies are created when the page is first opened, and are stored until the script deletes them, while they must be the same for all pages. After I made the CNC, a strange problem arose: those cookies that were created on the main page, the pages connected to it, are no longer seen and therefore create their own. Cookies are a global array! How can that be? Help me please! Thanks in advance!
Here is the code that creates the cookies, this is the shopping cart:
function saveCart() {
global $cart;
$cart = base64_encode(serialize($cart));
setcookie('cart', $cart, 0x7FFFFFFF);
}
function cartInit() {
global $cart;
if(!isset($_COOKIE['cart'])) {
$cart = array('swc_data_order' => strtoupper(randomString(5, 6)));
saveCart();
}
else {
$cart = unserialize(base64_decode($_COOKIE['cart']));
}
}
function addCartType($id, $amount) {
global $cart;
$cart[$id]['amount'] = $amount;
saveCart();
}
function deleteItemFromCart($id) {
global $cart;
unset($cart[$id]);
saveCart();
}
cartInit();
Answer the question
In order to leave comments, you need to log in
Show the code. it seems to me that the url for the cookie is registered incorrectly
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question