ASP Forms - A Baker's Dozen
(Page 3 of 5 )
Bakers must be dumb. I mean don't get me wrong: I love the incredible and all important work they do. But don't they know that a dozen is only equal to twelve and not thirteen? But who cares, we get that extra donut free of charge. So stick it to the baker. And shh...don't let them know.
If you want to store more than one piece of data in a cookie, you can. I won't stop you. When you do so, it is called a collection and the values inside are referred to as keys.
Here is how we create a cookie named "fortune" with multiple values:
<%
Response.Cookies("fortune") ("fortuneone") = "You will die a horrible death. Have a good day"
Response.Cookies("fortune") ("fortunetwo") = "You will meet a handsome stranger. Then he will rob you"
Response.Cookies("fortune") ("fortunethree") = "Life is like a box of vacuum cleaners. It sucks."
%>
Reading the Collection
Here, we learn to read the keys in our Cookie collection:
<html>
<body>
<%
Dim x, y
for each x in Request.Cookies
response.write("<p>")
If Request.Cookies(x).HasKeys then
for each y in Request.Cookies(x)
response.write(x & "/" & y & "=" & Request.Cookies(x) (y))
response.write("<br />")
next
else
Response.Write(x & "=" & Request.Cookies(x) & "<br />"
end if
response.write "</p>"
next
%>
</body>
</html>
How is that for some wacky code. Here is the result:
fortune/fortuneone=You will die a horrible death. Have a good day
fortune/fortunetwo=You will meet a handsome stranger. Then he will rob you
fortune/fortunethree=Life is like a box of vacuum cleaners. It sucks.
Next: Sessions >>
More ASP Code Articles
More By James Payne