• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt on Cookies

 
muthu kumaran
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I got one more doubt on cookies.
When the setMaxAge on a Cookie is set to zero , the spec says that
the cookie would be deleted. Is it like the client deletes the cookie
immediately on receiving it ? If so what is the use of sending the
cookie ?
Could anyone throw some light on this ?

Thanks
Muthu
 
vipul patel
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when the browser exits, cookie will be deleted.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dilip,
A zero value causes the cookie to be deleted. It does not wait for the browser to exit. However, this will happen if you pass -1 to setMaxAge.

muthu,
If so what is the use of sending the cookie ?

What do you mean ? You'll send the cookie because you want it to be deleted (the one you've set the max age to 0).
[ January 30, 2006: Message edited by: Satou kurinosuke ]
 
muthu kumaran
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou,
When the setMaxAge is set to 0, it means the cookie would be deleted immediately on reaching the client ( this is my understanding right now..may be I am wrong)

What I meant by "what would be the use of sending a cookie that gets deleted on reaching the client"
goes by the basic purpose of sending a cookie

A cookie contains some information , like session id which is sent back to the server but if a server itself sets the cookie's MaxAge as zero , it knows it can't get the cookie back from the client
as it would get deleted on the client side immediately on reaching it

So why would a server send a cookie with the MaxAge set to 0 ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand what you mean now

As you said, the server knows that the cookie won't be used anymore, but the client has to know it too. That is why the server says to the client "Oy, this cookie smells, throw it away"

If you want to know more, have a look at RFC 2109
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic