Jump to content

[SOLVED] Array Serializing and cookies


$cripts

Recommended Posts

Ok for some reason this cookie wont keep the array values and it will simply reset to only on value in the array

$shopitems = (isset($_COOKIE['shop_items'])) ? unserialize($_COOKIE['shop_items']) : array();
if(!$_GET['itemid'] || !is_numeric($_GET['itemid']))
{
}
else
{
$itemid = $_GET['itemid'];
$shopitems[$itemid] = $itemid.',1';
setcookie('shop_items',serialize($shopitems),0,'','');
}

wut this should do is when there is an itemid it will put it in the array of shopitems serialize it and set the cookie for later use the problem is that when there is allready an array serialized in the cookie it will not take that array values

so instead of saying there is allready a value in the array of shopitems[2] and i want to add shopitems[4] it will simply use shopitems[4] to set the array

And i tested it out on this which does the same thing and it works perfetcly fine....

$forum_review = (isset($HTTP_COOKIE_VARS['forum_view'])) ? unserialize($HTTP_COOKIE_VARS['forum_view']) : array();
$start = (!$_GET['start']) ? '0' : $_GET['start'];
$enter = $start + 10;
while($start < $enter)
{
$forum_review[$start] = '2';
setcookie('forum_view',serialize($forum_review),0,'','');
$start++;
}

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.