Forum Moderators: open

Message Too Old, No Replies

request.cookie problem

doesn't work first visit to the page, only the second.

         

Receptional Andy

2:04 pm on Mar 31, 2003 (gmt 0)



I have an ASP script that just will not work. It isn't even a particularly complicated script. I set a session cookie on preceeding pages, and just want to recall the cookie and split it into nice bite sized pieces. I set the cookie fine, but then when I try and recall the values I get errors, but only the first time I hit the page with the above code in it. The second time I hit the page it works fine. I'm not great with ASP, so it's probably an obvious error to the more experienced.

Anyone have any ideas where i'm going wrong?

IF Request.Cookies("session") <> "" THEN
all1= Request.Cookies("session")
all= unescape (all1)
MyArray= split(all,"&")
REF=MyArray(0)
QUE=MyArray(1)
END IF

The first time I call the script I get 'Subscript out of range errors' splitting the cookie values. Second time, no errors, everything works fine. Help!

Receptional Andy

1:06 pm on Apr 1, 2003 (gmt 0)



Any ASP-ers help me out with this?

chris_f

1:28 pm on Apr 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi ReceptionalAndy,

Tell Dixon I said hello and that I'm on to egg. :)

Regarding your problem, It sounds to me like the problem might be with the cookie duration. You must set a cookie duration. Also, I would put a space between the two double quotes on the line

IF Request.Cookies("session") <> "" THEN

Chris

Receptional Andy

1:38 pm on Apr 1, 2003 (gmt 0)



Hi Chris,
I'm not sure if duration explains it. I have the duration set to 0 (so the cookie expires at the end of the session), and also the cookie is set fine. That said, if I use the script on a non-session cookie it seems to work. Hmm.

chris_f

1:47 pm on Apr 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Andy,

Try these one by one:

1. Try the space between the two double quotes
2. Increase the cookie duration (try using a date)
3. The problem could be that the line:

IF Request.Cookies("session") <> "" THEN

suggests that there is a cookie, when there is not one.

Try

If Not Request.Cookies("session") = " " THEN

Chris