Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q5806 How do I set a cookie?

You are here: irt.org | FAQ | ASP | Q5806 [ previous next ]

ASP can set cookies quite easily. They are implemented as a collection in the ASP Response object, so you merely specify the name of the item in that collection and set it's value :

<%

' SET A TEXT STRING
Response.Cookies("myCookie") = "this value"

' SET THE RETURN OF A FUNCTION
Response.Cookies("myCookie2") = Now()

%>

Returning them is also easy:

<%

Response.Write Request.Cookies("myCookie") & "<br>"
Response.Write Request.Cookies("myCookie2")

%>

Alternately, if you are setting LOTS of cookies (tsk-tsk), you can
use the fact that they are in a collection to return them all:

<%

' cookie IS JUST AN ARBITRARY VARIABLE NAME
For each cookie in Request.Cookies
 Response.Write cookie & " = " &
 Request.Cookies(cookie) & "<br>"
Next

%>

©2018 Martin Webb