The trouble with cookies....
The trouble with cookies that I am finding is that when I set a cookie from the server, it takes a finite amount of time to transmit it and then read back the new value. It at least takes longer than it takes to display a page. This causes a problem in the logic of my site because I rely on the cookie to tell me something about the user. I need to be able to set a cookie (or some other state variable?). Then when I show the next web page I want the contents to reflect the new value of the cookie, however when I read the just-set cookie back, it has not yet been set to the new value! You can see what I mean by going to this page: http://kalandskolemusikk.no/?page=video If you click on 'hare', you have to do it twice (or click once and then reload) to get the title text to change blue (the same goes for 'snegle' to get it to change green) because when the cookie is sent on the first click, it has not been received back by the time the text is redisplayed. An obvious solution would be to have a 'parallel' local logic that changes the color anyway without checking the cookie but I am reluctant to do this because you are supposed to be able to come back to this page with the cookie already set from a previous session. Is there some way to do a 'blocking' setCookie, or is there some other way to set a session based state variable? -- Jeremy Cook <Jeremy.Cook@ii.uib.no> Parallab
On 22 May 2003 14:38:57 +0200, Jeremy Cook <Jeremy.Cook@ii.uib.no> wrote:
The trouble with cookies that I am finding is that when I set a cookie from the server, it takes a finite amount of time to transmit it and then read back the new value. It at least takes longer than it takes to display a page. This causes a problem in the logic of my site because I rely on the cookie to tell me something about the user.
I need to be able to set a cookie (or some other state variable?). Then when I show the next web page I want the contents to reflect the new value of the cookie, however when I read the just-set cookie back, it has not yet been set to the new value!
Yep, this is the way that cookies work. Best thing to do is separate your method for setting the cookie into a script, and call context.REQUEST.RESPONSE.redirect(yourPage) at the end of the script. This will ensure that the cookie is set before you try to read it. - seb -- Seb Potter Lead Developer Getfrank Limited
participants (2)
-
Jeremy Cook -
Seb Potter