Forum Moderators: open

Message Too Old, No Replies

Cookie Assistance

Page 1 to Page 2 OKAY - but back to Page 1 -fails

         

crashomon

6:44 pm on Aug 10, 2005 (gmt 0)

10+ Year Member



Hi everyone, I've got a situation that I can't seem to fix and I've been beating my head against the wall. I'm trying to pass a cookie value from page 1 to page 2 and back again. It works fine from 1 to 2, but when I go back to page 1, its showing values from an old, old cookie (in other words, its not pulling the newest values).

Here's a snippet of the relevant code for page one ("default.asp"):

<%
firstName=request.cookies("firstName")
lastName=request.cookies("lastName")
blackEye=request.cookies("blackEye")
favePic=request.cookies("favePic")
%>

and

<%
For Each cookie in Response.Cookies
Response.Cookies(cookie).Expires = now()+365
Next
%>

Which passes the values selected for these settings just fine to page two ("default_response.asp"):

<%
firstName=request("firstName")
lastName=request("lastName")
blackEye=request("blackEye")
favePic=request("favePic")
%>

and

<%
For Each cookie in Response.Cookies
Response.Cookies(cookie).Expires = now()+365
Next
%>

The user clicks on a link to go back
<a href="/default.asp">GO BACK </a>

and its showing values that are used from the VERY first time that the page was 'interacted with'.

This behavior is consistent across firefox and explorer.

Any thoughts? Any clues? Do I need to use a 'if then' test to have default 'update?

Thanks in advance,

Patrick

mrMister

7:44 pm on Aug 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you press back to view default.asp, you're seeing the original version as it's cached in your browser.

Hold shift and click refresh in your browser.

crashomon

8:07 pm on Aug 10, 2005 (gmt 0)

10+ Year Member



Hi thanks, but it doesn't work, it still reverts back to the original cookie value for all settings. IE or firefox, either one still goes back to 'first' cookie no matter what. I'm looking to pass the values from page 2 BACK to page 1. Does that make sense?

emsaw

10:33 pm on Aug 10, 2005 (gmt 0)

10+ Year Member



crashomon,

something like this?
*Disclaimer*
This is extremely sloppy code, but good enough for proof of concept to get you started in the right direction. HTH. - Mark

default.asp
--------
<% @Language="VBScript" %>
<%
'Option Explicit

Dim firstName, lastName, blackEye, favePic

firstName = Request.cookies("UserInfo")("firstName")
lastName = Request.cookies("UserInfo")("lastName")
blackEye = Request.cookies("UserInfo")("blackEye")
favePic = Request.cookies("UserInfo")("favePic")

Response.write "Dirty?: >" & Request.cookies("UserInfo")("Dirty") & "<<br>"
Response.Write "<b>Before</b>: <br>" & firstName & "<br>" & vbCrLf
Response.Write lastName & "<br>" & vbCrLf
Response.Write blackEye & "<br>" & vbCrLf
Response.Write favePic & "<br>" & vbCrLf

If Request.Cookies("UserInfo")("Dirty") <> "False" Then
Response.Write "<br>Loaded Initial Cookie values.<br>"
Response.Cookies("UserInfo")("Dirty") = "False"
Response.cookies("UserInfo")("firstName") = "John"
Response.cookies("UserInfo")("lastName") = "Doe"
Response.cookies("UserInfo")("blackEye") = "Yes"
Response.cookies("UserInfo")("favePic") = "CoteDAzure.jpg"
End If

firstName = Request.cookies("UserInfo")("firstName")
lastName = Request.cookies("UserInfo")("lastName")
blackEye = Request.cookies("UserInfo")("blackEye")
favePic = Request.cookies("UserInfo")("favePic")

Response.Write "<b>After</b> <br>" & firstName & "<br>" & vbCrLf
Response.Write lastName & "<br>" & vbCrLf
Response.Write blackEye & "<br>" & vbCrLf
Response.Write favePic & "<br>" & vbCrLf

%>

<a href="default_response.asp?ChangeValue=N">default_response.asp?ChangeValue=N</a><br><br>
<a href="default_response.asp?ChangeValue=Y">default_response.asp?ChangeValue=Y</a>
--------

default_response.asp
--------
<% @Language="VBScript" %>
<%
'Option Explicit

Dim firstName, lastName, blackEye, favePic

firstName = Request.cookies("UserInfo")("firstName")
lastName = Request.cookies("UserInfo")("lastName")
blackEye = Request.cookies("UserInfo")("blackEye")
favePic = Request.cookies("UserInfo")("favePic")

Response.Write "<b>Before:</b> <br>" & firstName & "<br>" & vbCrLf
Response.Write lastName & "<br>" & vbCrLf
Response.Write blackEye & "<br>" & vbCrLf
Response.Write favePic & "<br>" & vbCrLf

If Request.QueryString("ChangeValue") = "Y" Then
Response.Write "Changed Cookie values.<br>"
Response.Cookies("UserInfo")("Dirty") = "True"
Response.cookies("UserInfo")("firstName") = "Joe"
Response.cookies("UserInfo")("lastName") = "Blow"
Response.cookies("UserInfo")("blackEye") = "No"
Response.cookies("UserInfo")("favePic") = "MountainBiking.jpg"
End If

firstName = Request.cookies("UserInfo")("firstName")
lastName = Request.cookies("UserInfo")("lastName")
blackEye = Request.cookies("UserInfo")("blackEye")
favePic = Request.cookies("UserInfo")("favePic")

Response.Write "<b>After</b> <br>" & firstName & "<br>" & vbCrLf
Response.Write lastName & "<br>" & vbCrLf
Response.Write blackEye & "<br>" & vbCrLf
Response.Write favePic & "<br>" & vbCrLf

%>

<a href="default.asp">default.asp</a>
--------

crashomon

6:35 pm on Aug 12, 2005 (gmt 0)

10+ Year Member



hey thanks! i'm going to test it out.

Patrick