Entry
Array: setcookie('first[0]',"$wirefloatbur"); the array goes to 24. I'm having data problems with locations 21,22,23.data is not there when printed
Nov 24th, 2004 07:48
Michael Richardson, George Federuik,
Well, I'm new to PHP but from what I've read, each site can only send a
max of 4KB or 20 cookies (which ever comes first) per website. {This
may depend on what version your using, but I read this in "PHP 4:A
Beginner's Guide" not too long ago.
At a guess, I'd say you are using a for loop to set the cookies
something like this:
for($i=0;$i<25;$i++)
{
setcookie('first[$i]',"$wirefloatbur");
}
What is happening even though you are loading an array here, you are
setting a cookie for each element, everytime you run the for loop. Your
max is 20 cookies per site, so you fill the cookies "first[0]" thru
"first[19]" which is your limit, then the remainders keep covering the
last one. {I could be wrong, but each extra cookie replaces the last
one entered (LIFO or Last In First Out replacement). What you should
do...and this was recommended by the same text that I read... is to load
the first[] array first, then set one cookie that holds the entire array.
for($i=0;$i<25;$i++)
{
$first[$i]="$wirefloatbur";
}
$first = serialize($first);
setcookie("first","$wirefloatbur");
//then when you need the values "unpack the pieces" and your
// array will be back to normal. Strip the slashes...they're
// added be the serialize() function
$first = unserialize(stripslashes($first));
This loads first with all your values as an array, serializes it so that
it can be passed as one string more easily in the cookie, then sets ONE
cookie with all the values. The advantage is that you have 19 more
cookies available to you now that could all have many value in each.
This does not get around the 4KB limit though so be warned.