View Full Version : Cookies???
JackFruit3D
10-07-2002, 01:23 AM
I'm wanting to randomly make basic entries into a cookie as ppl browse throu my site, now i can easily throw an entry into a cookie using a Session("XXX") = "blah blah blah"... but i want to be able to dump all the entries in that cookie to a page in a large list, without knowing the name on the entry ie "XXX".
Or alternatively i want an array created in a cookie where i can easily dump the array to a page with both a description and value.?ż
any ideas.?ż!
whammy
10-07-2002, 03:39 AM
Huh? :confused: Could you perhaps explain in English what you're trying to accomplish (no code)?
"Array in a cookie"? I'm thinking you want to use cookie keys or the Scripting.Dictionary object - but from your explanation I really have no idea...
http://www.w3schools.com/asp/asp_cookies.asp
http://www.w3schools.com/asp/asp_sessions.asp
http://www.w3schools.com/asp/asp_ref_dictionary.asp
JackFruit3D
10-07-2002, 03:46 AM
I want to keep a whole bunch of various and constantly changing variables and their values (most variables pulled from a database and needed on a final page) .
So i fugured throw them all into a cookie then when i finally reach the final page i can bring them all into one page by retreiving them from the cookie.
any clearer?
whammy
10-07-2002, 04:01 AM
Sure, that makes a lot more sense - in which case I was correct, and you just need to make a cookie key for each variable, and then change it on each page where you want... i.e.
Response.Cookies("cookiename")("variablename") = "blah"
For more information, see the link I posted above.
:)
JackFruit3D
10-07-2002, 04:06 AM
ok
but the in ... Response.Cookies("cookiename")("variablename") = "blah"
the cookiename is pulled from a database so i have no idea if any particular entry and it value from the db is in the cookie...
I don't want to write down 50,000 lines of code incase every possible entry on my db has been selected, just so that on the final page i can see maybe 10 cookie entries
.... if that made sense
glenngv
10-07-2002, 04:30 AM
Response.Cookies(rs("cookiename"))("variablename") = "blah"
where rs is the recordset object that contains the cookie name from the database, and cookiename is the field name in the db
JackFruit3D
10-07-2002, 04:54 AM
ok...
but like i said if i did that my final page would need 50,000 lines of code (one for each entry)
ie cookie name, value
item, 123
person, bob
place, outside
color, green
......
i need to avoid the masses of coding on the final page!!!!!
i need to be able to retrieve any and ALL entries in a cookie without knowing the names of them
glenngv
10-07-2002, 05:03 AM
but isn't that in a loop?
while not rs.EOF
Response.Cookies(rs("cookiename"))("variablename") = "blah"
rs.movenext
next
JackFruit3D
10-07-2002, 05:08 AM
that would only happen if i put every single entry in my database into the cookie.....
not what i want to do
i want to be able to select what i put in the cookie,
and have a page that can tell me wat i have select from various other pages and their values
glenngv
10-07-2002, 06:16 AM
try this:
'set:
Response.Cookies("mycookie")("item") = "123"
Response.Cookies("mycookie")("person") = "bob"
Response.Cookies("mycookie")("place") = "outside"
Response.Cookies("mycookie")("color") = "green"
'get:
for each ck in request.cookies
response.write ck & " = " & request.cookies(ck) & "<br>"
next
JackFruit3D
10-07-2002, 09:54 PM
is there any simple way to break up the response...
mycookie = item=123&person=bob&place=outside&color=green
into variables...
ie.
mycookie_item=123
mycookie_person=bob
mycookie_place=outside
mycookie_color=green
so i can then manipulate them a little and put them into text fields on a form.
??????!!!!*!!!!żżżżżżż
glenngv
10-08-2002, 01:54 AM
doesn't this work?
for each ck in request.cookies
response.write ck & " = " & request.cookies(ck) & "<br>"
next
JackFruit3D
10-08-2002, 01:56 AM
that writes it all to the screen but i need the values and the names to be variables
whammy
10-08-2002, 02:06 AM
So make them variables... or do you want glenngv to explain that as well, without trying to learn it yourself? No offense, but c'mon man... do a little bit of research and testing on your own?!?
Hint... right there you could split that up into arrays using "&"... look at how you can split strings into arrays using the Split() function - i.e. google it "Split() ASP". That should help you out a LOT.
somestring = "item=123&person=bob&place=outside&color=green"
If I split that by "&" first, that will give me an array I can loop through... then I can split each value by "=" and it will give me the variable name AND value...
JackFruit3D
10-08-2002, 02:31 AM
whammy...
appoligees
didn't see your eariler post with and asp cookie page.
a much simpler solution has arrived
thanx
whammy
10-08-2002, 02:42 AM
Yes. Cookie keys. :D
glenngv
10-08-2002, 02:46 AM
Originally posted by whammy
So make them variables... or do you want glenngv to explain that as well, without trying to learn it yourself? No offense, but c'mon man... do a little bit of research and testing on your own?!?
thanks whammy! :)
we are all here in this forum not to be spoon-fed. sometimes, we just need to point them in the right direction, the actual solution that exactly fits their needs would still depend on them. This way, they will learn more independently. :)
whammy
10-08-2002, 02:49 AM
Thank YOU, glenngv - at least I don't feel alone.
Recently I've been fairly fed up with a lot of the posts in here, to be honest. It seems that not many people are really trying to figure things out for themselves... a lot of the time I am really bad at explaining something I "know"... and sometimes totally misread what a person is really trying to do (since they don't know enough to explain what it actually IS they are trying to do), and it just confuses the situation worse...
It really helps if they at least visit:
http://www.w3schools.com
I could almost swear that most basic scripting problems (in almost any language) could be solved by making frequent visits there and just playing around... I was able to make some really awesome scripts just by playing around with their examples... :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.