www.daleanderson.ca - /edb/download/arbitrary guinea pig file for source viewing.asp (Source)  

[To Parent Directory]  
 
  Turn on line numbering  Turn off syntax highlighting

<%
' 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


%>
<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

' 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="<%=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>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>The Code</h2>
<pre>
&lt;%
' 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(&quot;PATH_INFO&quot;)
NameOfThisPage = StrReverse(NameOfThisPage)
If Instr(NameOfThisPage,&quot;/&quot;) &gt; 0 Then
	CutTo = Instr(NameOfThisPage,&quot;/&quot;)
	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(&quot;name&quot;))
strCookieValue = CStr(Request.QueryString(&quot;value&quot;))

' If no name is passed in then we don't do anything
If strCookieName &lt;&gt; &quot;&quot; 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 &lt;&gt; &quot;&quot; Then
		Response.Cookies(strCookieName).Expires = Date() + 1
	Else
		Response.Cookies(strCookieName).Expires = Date() - 1
	End If
	Response.Buffer = True
	Response.Redirect NameOfThisPage
End If
%&gt;
</pre>


<h2>Implimentation</h2>
<pre>
&lt;!-- Regurgitate Cookies --&gt;
&lt;%
Dim Item
For Each Item in Request.Cookies
  response.write &quot;&lt;br&gt;&quot; &amp; Item &amp; &quot;=&quot; &amp; Request.Cookies(Item) &amp; &quot;&lt;A HREF=&quot; &amp; NameOfThisPage  &amp; &quot;?name=&quot; &amp; Server.URLEncode(Item) &amp; &quot;&gt;Delete this cookie!&lt;/A&gt;&quot;
Next
%&gt;



&lt;!-- Cookie adding form --&gt;
&lt;FORM ACTION=&quot;&lt;%=NameOfThisPage%&gt;&quot; METHOD=&quot;get&quot;&gt;
&lt;INPUT TYPE=&quot;text&quot; NAME=&quot;name&quot;&gt;
&lt;INPUT TYPE=&quot;text&quot; NAME=&quot;value&quot;&gt;
&lt;INPUT TYPE=&quot;submit&quot; VALUE=&quot;Add Cookie!&quot;&gt;
&lt;/FORM&gt;
</pre>




<hr>
</body>
</html>




Dale's Enhanced Directory Browser and ASP Source Viewer, v1.6.2 (2009/12/08)