Hi,
I'm having a few problems trying to get a script to work correctly. I'm trying to create a sort of shopping cart where items can be added to a list. The items cannot be duplicated and are stored in a cookie. I've put some echo statements in to try and debug where it is going wrong but i'm at a loss.
<?
if(isset($_GET['id']))
{
echo "ID is available - ID=$id...<br>";
if(isset($_COOKIE['testcookie']))
{
echo "Cookies are set...<br>";
echo "Creating an array with data stored in the cookie...<br>";
$thearray = unserialize(stripslashes($_COOKIE['testcookie']));
echo "Adding the current ID to the array... <br>";
$thearray[]=$id;
echo "Removing any duplicate entries in the array...<br>";
$thearray = array_unique($thearray);
echo "Putting the array into a string...<br>";
$thestring = serialize($thearray);
}
else
{
echo "Cookies are not set...<br>";
echo "Creating an array and adding the current ID=$id...<br>";
$thearray[]=$id;
echo "Putting the array into a string...<br>";
$thestring = serialize($thearray);
}
echo "Updating the cookie with the string...<br>";
setcookie('testcookie', $thestring, time()+60);
echo "Putting the updated array into a new string separated by comma's...<br>";
$comma_separated = implode(",", $thearray);
echo "OUTPUT: - $comma_separated<br>";
}
Thanks