Jump to content

Array in a cookie


martyng

Recommended Posts

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");
?>
Link to comment
Share on other sites

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

[code]
$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");
[/code]

To retrieve the item you would do something like this:
[code]echo $_COOKIE['sbh']['fname'];[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.