473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

cookies with multple vals

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
2 1903
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Maverick | last post by:
Hello all, I read some good reviews about jakarta HTTPClient about its session and cookies management system and fancied giving it a try as a learning exercise but somehow I don't seem to be able...
4
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with storing cookies with ASP? I'm trying this with two browsers: One is IE 6.0 with cookies set to 'prompt'. This has been working properly as any...
20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
6
by: Mark | last post by:
Hi... I've come across some weird bug with Response.Cookies. Or maybe it will be called "by design" but for the life of me I can't figure out what purpose it would serve. If you're setting a...
11
by: Mark | last post by:
We use cookies to maintain some state information about a users session. They are not file based due to the fact that we don't specify a expiration date. They go away when the session ends. I...
8
by: CDARS | last post by:
Hi all, I have a confusing question on ASP.NET cookies usage: 1> Response.Cookies("test").value = Now 2> Response.Write(Request.Cookies("test").value) 3> 4> Response.write("<hr>") 5>...
6
by: Stephane | last post by:
Hi, I have a login page where if the user wants his access codes to be saved are set into a cookie. In the logout page, I want to delete those cookies. I tried this and this is not working at...
0
by: rn5a | last post by:
This is how I am creating & then reading cookies: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) 'create cookies Response.Cookies("UserName").Value = "Ron"...
1
by: charmgirl | last post by:
hi, is it possible to have multple forms in a page. if yes than how to read data from multople forms ?
5
by: KingKen | last post by:
I have a situation whereby I have to enter many records in a db that only have one field that changes. For example software installed on a computer would give you many different rows of data with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.