[Zope] The trouble with cookies....

Seb Potter seb@getfrank.com
Thu, 22 May 2003 14:07:30 +0100


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