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
https://forums.phpfreaks.com/topic/45689-solved-array-serializing-and-cookies/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.