View Single Post
Old 05-02-2011, 04:35 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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);

__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote