Turn on line numbering Turn off syntax highlighting
<%
Dim NameOfThisPage, CutTo
NameOfThisPage = Request.Servervariables("PATH_INFO")
NameOfThisPage = StrReverse(NameOfThisPage)
If Instr(NameOfThisPage,"/") > 0 Then
CutTo = Instr(NameOfThisPage,"/")
NameOfThisPage = Left(NameOfThisPage,(CutTo - 1))
End If
NameOfThisPage = StrReverse(NameOfThisPage)
Dim strCookieName
Dim strCookieValue
strCookieName = CStr(Request.QueryString("name"))
strCookieValue = CStr(Request.QueryString("value"))
If strCookieName <> "" Then
Response.Cookies(strCookieName) = strCookieValue
If strCookieValue <> "" Then
Response.Cookies(strCookieName).Expires = Date() + 1
Else
Response.Cookies(strCookieName).Expires = Date() - 1
End If
Response.Buffer = True
Response.Redirect NameOfThisPage
End If
%>
<html>
<head>
<title>ASP Cookies</title>
<style type="text/css">
body,td,th,input {font-family: "Verdana, Arial, Helvetica, sans-serif"; font-size: 8pt; }
h2,h1,H1,H2 {font-family: "Arial, Helvetica, sans-serif"; }
</style>
</head>
<body>
<H1>ASP Cookies</H1>
<hr>
<TABLE BORDER="2">
<THEAD>
<TH>Cookie Name</TH>
<TH>Cookie Value</TH>
<TH>Action</TH>
</THEAD>
<%
Dim Item
For Each Item in Request.Cookies
%>
<TR>
<TD><% = Item %></TD>
<TD><% = Request.Cookies(Item) %></TD>
<TD><A HREF="<%=NameOfThisPage%>?name=<%= Server.URLEncode(Item) %>">Delete</A></TD>
</TR>
<%
Next
%>
<!-- Cookie adding form -->
<FORM ACTION="<%=NameOfThisPage%>" METHOD="get">
<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>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<h2>The Code</h2>
<pre>
<%
' Just in case you wanna change the name of this page, you won't need
' to worry about updating the form or any links.
Dim NameOfThisPage, CutTo
NameOfThisPage = Request.Servervariables("PATH_INFO")
NameOfThisPage = StrReverse(NameOfThisPage)
If Instr(NameOfThisPage,"/") > 0 Then
CutTo = Instr(NameOfThisPage,"/")
NameOfThisPage = Left(NameOfThisPage,(CutTo - 1))
End If
NameOfThisPage = StrReverse(NameOfThisPage)
' This script handles both the adding and deleting of cookies
Dim strCookieName ' The name of the cookie we're processing
Dim strCookieValue ' The value to be assigned to it
' Get the values passed in by the other script
strCookieName = CStr(Request.QueryString("name"))
strCookieValue = CStr(Request.QueryString("value"))
' If no name is passed in then we don't do anything
If strCookieName <> "" Then
' Set the value of the cookie
Response.Cookies(strCookieName) = strCookieValue
' If the value is nothing then we expire the cookie
' by setting it's expiration date to yesturday,
' otherwise we set it to expire tomorrow.
If strCookieValue <> "" Then
Response.Cookies(strCookieName).Expires = Date() + 1
Else
Response.Cookies(strCookieName).Expires = Date() - 1
End If
Response.Buffer = True
Response.Redirect NameOfThisPage
End If
%>
</pre>
<h2>Implimentation</h2>
<pre>
<!-- Regurgitate Cookies -->
<%
Dim Item
For Each Item in Request.Cookies
response.write "<br>" & Item & "=" & Request.Cookies(Item) & "<A HREF=" & NameOfThisPage & "?name=" & Server.URLEncode(Item) & ">Delete this cookie!</A>"
Next
%>
<!-- Cookie adding form -->
<FORM ACTION="<%=NameOfThisPage%>" METHOD="get">
<INPUT TYPE="text" NAME="name">
<INPUT TYPE="text" NAME="value">
<INPUT TYPE="submit" VALUE="Add Cookie!">
</FORM>
</pre>
<hr>
</body>
</html>
|