By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,892 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,892 IT Pros & Developers. It's quick & easy.

cookies with multple vals

P: n/a
I want a cookie that can have about 5 values. I was told to do something
like this:

to set the cookie the first time:
setcookie("questions[]",$_POST['questionid'],time()+60*60*24,"/","",0);

then to add valus to this cookie later:
setcookie("questions[]",$_POST['questionid']);

the problem is that when I do this, the cookie's first value is just getting
replaced over and over again.

How do I handle a cookie so I can just keep pushing values on to it n times
so that at the end I have an array with n values??

--
Alexander Ross
al******@bleen.net
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Fri, 29 Aug 2003 13:51:55 -0500, in message
<fhN3b.300494$uu5.64849@sccrnsc04>, the AI program named "Alexander Ross"
<al******@bleen.net> randomly printed:
I want a cookie that can have about 5 values. I was told to do something
like this:

to set the cookie the first time:
setcookie("questions[]",$_POST['questionid'],time()+60*60*24,"/","",0);

then to add valus to this cookie later:
setcookie("questions[]",$_POST['questionid']);

the problem is that when I do this, the cookie's first value is just
getting replaced over and over again.

How do I handle a cookie so I can just keep pushing values on to it n
times so that at the end I have an array with n values??

--
Alexander Ross
al******@bleen.net


You could store the values in an array. Then you would
serialize() and base64_encode() it to put it
into a cookie.

To get the array back, base64_decode() it and
unserialize() it.

Then add whatever items you want to the array
and do it all over again.

BTW: It's probably not a good idea to put too much
junk into the HTTP header; it might reduce efficiency.
If you have an array with 1000 elements, I advise against
putting it into a cookie because it would slow things
down.

Just use a session variable. Putting an array into a
session is just too easy.

Jul 16 '05 #2

P: n/a
Alexander Ross wrote:
I want a cookie that can have about 5 values. I was told to do something
like this:

to set the cookie the first time:
setcookie("questions[]",$_POST['questionid'],time()+60*60*24,"/","",0);

then to add valus to this cookie later:
setcookie("questions[]",$_POST['questionid']);

the problem is that when I do this, the cookie's first value is just getting
replaced over and over again.
What ya need to do is something like this:

setcookie("questions[1]","qid1");
setcookie("questions[2]","qid2");

you can then get at them with this:

foreach ($_COOKIE['questions'] as $name => $value) {
print "$name: $value <br />";
}

which will output:

1: qid1
2: qid2

....I think. :)

MK.
How do I handle a cookie so I can just keep pushing values on to it n times
so that at the end I have an array with n values??

--
Alexander Ross
al******@bleen.net


--
MeerKat

Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.