sas

Topic: ASP


Cookies

Creating an ASP cookie is exactly the same process as creating an ASP Session. Once again, you must create a key / value pair where the key will be the name of our "created cookie". The created cookie will store the value which contains the actual data.

Retrieving Cookies

To get the information we have stored in the cookie we must use the ASP Request Object that provides a nice method for retrieving cookies we have stored on the user's computer. Below we retrieve our cookie and print out its value.



<%
This table lists all of our cookies on your computer.<BR>

<BR>

<!-- Cookie display table -->
<TABLE BORDER="2">
<THEAD>
<TH>Cookie Name</TH>
<TH>Cookie Value</TH>
<TH>Delete Cookie</TH>
</THEAD>
<%
Dim Item

' Loop through the cookie collection displaying each cookie we find
For Each Item in Request.Cookies
%>
<TR>
<TD><% = Item %></TD>
<TD><% = Request.Cookies(Item) %></TD>
<TD><A HREF="cookie_process.asp?name=<%= Server.URLEncode(Item) %>">Delete this cookie!</A></TD>
</TR>
<%
Next
%>
</TABLE>

<!-- Cookie adding form -->
<FORM ACTION="cookie_process.asp" METHOD="get">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD>Cookie Name:</TD>
<TD>Cookie Value:</TD>
<TD></TD>
</TR>
<TR>
<TD><INPUT TYPE="text" NAME="name"></INPUT></TD>
<TD><INPUT TYPE="text" NAME="value"></INPUT></TD>
<TD><INPUT TYPE="submit" VALUE="Add Cookie!"></TD>
</TR>
</TABLE>

</FORM>

%>

 


Prev