Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
if (isset($_GET["ekle"])) {
echo "test";

$id = $_GET["ekle"];

setcookie("urun[" . $idi . "]", true, time() + 99999);
header("location:index.php");
} else {


echo "test2";
}
********************
cart part code
*******************
if (isset($_COOKIE['urun'])) {
echo "var";
} else {
echo "yok";
}


if (isset($_GET['boşalt'])) {
foreach ($_COOKIE['urun'] as $key => $val) {

setcookie("urun[" . $idi . "]", true, time() - 99999);
}

header("location:index.php");
} else {
echo "yok";
}

What I have tried:

When the id is clicked on the a tag, the id information is cookied.
It will take the id on the cart page to transfer and add it from mysql query accordingly.
Posted
Updated 15-Jun-22 21:45pm

1 solution

You set a cookie called urun[...]. You then test to see if a completely different cookie called urun has been set.

The cookie name you pass to $_COOKIE needs to precisely match the name you pass to setcookie.

If you want to store multiple values in a single cookie, you need to use a single cookie name, and serialize the values into the cookie value. For example: How do you set a php cookie with multiple values? - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900