views:

38

answers:

1

How is, for example, a shopping cart cookie set?
Once something is added to the cart it "creates" the cookie but how does the next page know to send a new http header with this new cookie to the client?

How is a cookie dynamically set based on user input? Is this functionality dependent on anything else?

I did see this example, but I am missing something.

Any help is appreciated, thanks.

CGI-C

+3  A: 

This is a typical set of steps.

  1. You submit a HTML form to /add_item. You don't send any Cookie header.
  2. The script at /add_item looks at your HTTP request.
  3. It sees that you did not send a Cookie header with your request.
  4. It creates a session for you. That means a set of variables (e.g. a list of items in your cart) are mapped to a unique identifier for your visit. Sessions really only exist on the server. The cookie is all the browser sees.
  5. It adds the item you added to your session.
  6. It then sends the output of the "Item Added!" page with a Set-Cookie header. That header contains the new session identifier.
  7. You add another item in your cart. This time, you send a Cookie header with the same ID the server gave you before.
  8. The server sees you already have a session ID so it does not create a new session.
  9. It adds the new item to your existing session.
  10. It sends the new "Item Added!" page with the same Set-Cookie header as before.
Matthew Flaschen
thanks............
Tommy