Jump to content


Photo

Array in a cookie


  • Please log in to reply
1 reply to this topic

#1 martyng

martyng
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 28 February 2006 - 05:17 PM

Hi
I'm trying to have an array to maintain the id's of some favourite items, like a shopping cart but no that complicated. I can't get it to add to the array tho, can anyone help?

<?php
// get id from url
if (isset($HTTP_GET_VARS['setid'])) {
$setid = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['setid'] : addslashes($HTTP_GET_VARS['setid']);
}
// check if cookie set and if so add new setid on the end
if(isset($feature)) {
echo $featureid;
$featureid = $featureid .= ','.$setid;
} else { // cookie not set yet
// only one entry so add as is
$featureid = $setid;
}
setcookie("feature", $featureid, time()+604800); /* Expires in a week */
$URL="./lightbox.php";header ("Location: $URL");
?>

#2 camdagr81

camdagr81
  • Members
  • PipPipPip
  • Advanced Member
  • 43 posts
  • LocationColumbus, Oh - United States

Posted 15 February 2007 - 04:48 PM

cookies auto array, all you have to do is specify the name of the item when adding it to the cookie.

	$time = time() + 360000;
	setcookie("sbh[id]", "$id", "$time", "/", ".sbhmed.com");
	setcookie("sbh[uname]", "$uname", "$time", "/", ".sbhmed.com");
	setcookie("sbh[fname]", "$fname", "$time", "/", ".sbhmed.com");
	setcookie("sbh[ulevel]", "$ulevel", "$time", "/", ".sbhmed.com");
	setcookie("sbh[email]", "$email", "$time", "/", ".sbhmed.com");
	setcookie("sbh[date]", "$date", "$time", "/", ".sbhmed.com");

To retrieve the item you would do something like this:
echo $_COOKIE['sbh']['fname'];

Powered by... Ramen. Fueled by Redbull
ITTAGAKIMASU!!!!!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users