Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q5806 How do I set a cookie?

irt.org | Knowledge Base | ASP | Q5806 [ previous next ]

Q5806 How do I set a cookie?

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

%>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.