Apologies in advance as I am a noob to PHP and progaming more generally.
Ok, I have a
setcookie.php script which is set to include on other scripts, which goes as follows:
Code:
<?php
if (isset ($_COOKIE['jumpinjakes']))
// do nothing if cookie 'jumpinjakes' is set
{
}
else // if cookie is unset then create cookie
{
$expiry = time() + 300 ; // expires variable = 5 Minutes
$identifier = uniqid (); // function generates unique session identifier
setcookie ("jumpinjakes[session]",$identifier,$expiry); // sets the 'jumpinjakes' session cookie - value as per $identifier - expires in 5 min
setcookie ("jumpinjakes[basket]"," ",$expiry); // sets the 'jumpinjakes' basket cookie - blank value - expires in 5 minutes
?>
The
Index.php script starts with:
Code:
<?php
session_start(); //required for cookie to function
?>
Then later a form is created, as follows:
Code:
<?php
"<form action='basket.php' method='request'>".
"<input type='hidden' value='$album' name='alb'>".
"<input type='hidden' value='add' name='action'>".
"<input type='submit' value=' add to basket '>".
"</form>".
?>
So on clicking the button it goes to
basket.php which starts with:
Code:
<?php
setcookie("jumpinjakes[basket]", $_REQUEST['alb'],300);
echo $_COOKIE['jumpinjakes']['basket'];
?>
I am looking to write the value of 'alb' to this 'basket' cookie. I think this is the correct syntax?
At this point I am looking to retrieve the value of [jumpinjakes][basket] cookie and assign it to a variable and echo it. So far my attempts have not worked.
I also want to append the 'alb' value to the 'basket' cookie should the cookie already contain values so that the basket contents isn't overwritten all the time.
My thoughts were:
Code:
<?php
if ($basket)
{
$basket .= ','. $alb;
}
?>
This is wrong, including the fact this condition will always be true.
Any help would be very apprecicated - Thanks!