PDA

View Full Version : Creating a shopping cart using PHP cookies



leo76uk
18 Jul 2010, 06:13 PM
Hi everyone,
I am creating a shopping cart using cookies. The item is post method form which can be $cart = $_REQUEST['item']. I am trying to create an array of requested items using
<?php
if ($cart) {
$cart .= ',' .$_REQUEST['item'];
} else {
$cart = $_REQUEST['item'];
}
setcookie( "product", $cart,time()+86400);
?>
But not able to retrieve data using the following so the get items from the database.
<?php
if ($cart) {
$items = explode(',',$cart);
foreach ($items as $item) {
echo $item;
}
}
?>
Can anybody give me the solutions?

Asperon
19 Jul 2010, 04:57 AM
your cookie is set as "product" so, in PHP you use $_COOKIE['product'] to retrieve the cookie that you saved.