On 2011-08-03 14:15 -0700, webpybuntu wrote:
> it writes (or attempts to write) a cookie, reads it back, and then
> deletes it. it tests whether it read the correct value. However, using
> code like this, I always get None for val2 despite cookies being
> enabled. Why isn't this working and how can I make it work?
> Thanks.

Because that's not how HTTP works. Here's how a normal work flow works:

1: Browser > Server "Howdy!"
2: Browser < Server "Oh! Hi, here's a cookie" (cookie attached)

3: Browser > Server "I need some stuff. And btw, here's the cookie"
4: Browser < Server "Hm, yes, that's my cookie. Ok. here's the stuff"

or, it might go like this:

1. Browser > Server "Hello!"
2. Browser < Server "Hi, man. How about a cookie?" (cookie attacked)

3. Browser > Server "I need some things."
4. Browser < Server "Hm, you don't seem to have the cookie on you..."

As you can see, there's always a request-response cycle in pairs. With
each request-response, the opportunity to set the cookie is when you are
making a response, and the browser then decides if it wants to show the
cookie next time it talks to the server. So the opportunity to check the
cookie is next response.

Now the problem is the "next response". There isn't such a thing as next
response (unless you are 100% sure that your web app is only ever used
by one and the same browser that is). The illusion of the next response
is created using cookies and sessions. So if the browser didn't set the
cookie you sent it, you never know when that same browser comes to you
again.

You don't have to worry about cookies to begin with. You should worry
about the problem you are trying to solve. Are you trying to track the
browser, to see if it's the same one you talked to before? Is there a
need to know if it's the same browser or maybe the operation you are
performing doesn't have to differentiate between different browsers,
etc. Those are the problems you should focus on.

-- 
Branko Vukelic
[email protected]
[email protected]

Lead Developer
Herd Hound (tm) - Travel that doesn't bite
www.herdhound.com

Love coffee? You might love Loveffee, too.
loveffee.appspot.com

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to