Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP classic - cookies not persistent

Status
Not open for further replies.

Teamco

Programmer
Oct 22, 2003
3
GB
I am looking at cookies for the first time
My code is below
When I run the scipt the cookie is set and as I run it again using a FORM to reschedule and again my counter increments, then I close the browser, and restart and I am expecting the cookie to be found now and continue counting where I left off before. What I get is no cookie found so the count starts at 1 again
This is not what I was expecting
I have internet options->privacy set to "accept all cookies"
Running Win2k Pro
Any ideas, where is my code or thinking astray?


<% @language=vbscript %>
<% Option Explicit %>
<%
Dim k, item, strX, key
Response.write("<HTML><HEAD><TITLE>Cookie testing</TITLE></HEAD><BODY>")
Response.write("<h2>Processing Cookies</h2>")

response.write("<FORM name=fm1 ACTION=cookies2.asp method=GET>")
response.write("<INPUT name=pass type=submit value='GO'>")
response.write("</FORM>")

response.write("<p>Before<br>JWtest(" & request.cookies("JWtest") & ")JWtest1(" & request.cookies("JWtest1") & ")")
k = request.cookies("JWtest")
if k="" then
response.Cookies("JWtest")=1
response.Cookies("JWtest").expires = date + 365
response.Cookies("JWtest1")="john@lortim.demon.co.uk"
else
response.Cookies("JWtest")= k + 1
end if
response.write("<br>After<br>JWtest(" & request.cookies("JWtest") & ") JWtest1(" & request.cookies("JWtest1") & ")")
Response.write("</BODY></HTML>")
%>
 
Code:
<%
  If LEN(Request.Cookies("k")) = 0 Then
   Response.Cookies("k") = 0
   Response.Cookies("k").expires = Date + 30
   sLast = 0
   sCurrent = 1
  Else
   Response.Cookies("k") = Request.Cookies("k") + 1
   Response.Cookies("k").expires = Date + 30
   sLast = Request.Cookies("k") 
   sCurrent = sLast + 1
  End If

  Response.write "<HTML><HEAD><TITLE>Cookie testing</TITLE></HEAD><BODY>" & _
                 "<h2>Processing Cookies</h2>" & _
                 "<FORM name=""fm1"" ACTION=""" & Request.ServerVariables("SCRIPT_NAME") & """ method=""GET"">" & _
                 " <INPUT name=""pass"" type=""submit"" value=""GO"">" & _
                 "</FORM>" & _
                 "<p>Before: (" & sLast & ")<br>" & _
                 "<p>After: (" & sCurrent & ")" & _
                 "</BODY></HTML>"
%>
 
Thank you kindly
but I do not understand why that works
Is it that cookie procesisng must complete BEFORE any response.write occurs?
if so, I really did not read that anywhere
further comments appreciated, but you solved it for me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top