session_start() is not required for cookies. Although this said you really should be using sessions instead of cookies anyway - cookies are extremely unreliable and under the full control of the user (who of course can not be trusted).
In fact, convert this to sessions, as its a lot easier to deal with than cookies.
PHP Code:
<?php
session_start();
if (!isset($_SESSION['jumpinjakes']))
{
$_SESSION['jumpinjakes']['session'] = uniqid();
$_SESSION['jumpinjakes']['basket'] = array();
}
?>
And in basket:
PHP Code:
<?php
session_start();
if (isset($_REQUEST['alb'])) // This really should be a forced GET/POST (there is no 'request' method in forms btw)
{
$alb = $_REQUEST['alb'];
if (isset($_SESSION['jumpinjakes']['basket'][$alb]))
{
$_SESSION['jumpinjakes']['basket'][$alb] += 1;
}
else
{
$_SESSION['jumpinjakes']['basket'][$alb] = 1;
}
}
I'm lazy, but something like that is what you want. You could hash the $alb itself (I hate using strings with potential spaces, I don't know why), and add in both a count and title offset to the arrays. Iteration of the above would simply be:
PHP Code:
foreach ($_SESSION['jumpinjakes']['basket'] AS $item => $quantity)
{
printf("%d of %s\n", $quantity, $item);
}