Forum Moderators: coopster
----------
<?
//retrieving and assigning cookie
$cart = $_COOKIE['cart'];
//if cookie is empty
if (empty($cart) ¦¦!isset($cart)) { setcookie("cart[i]", 1); $cart = $_COOKIE["cart"]; }
$max = $cart[1];
//finds last position of cookie array
for ($i = 1; $i <= sizeof($cart); $i++)
{
if ($cart[$i] > $max) { $max = $cart[$i];}
}
//increment array position
$max++;
//attempts to set cookie (success)
if(setcookie("cart[$max]", $max)){
echo "Cookie set!<br>\n";
}
//failed to set cookie
else{ echo "Failed to set cookie <br>\n"; }
//prints all elements of cookie (array) cart
if(!empty($cart)){
for ($j = 1; $j <= sizeof($cart); $j++){
$temp = $cart[$j];
echo "\$cart[$j] : $temp <br>\n";
}
}
?>
--------
-khanh