• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

expire cookie

 
arona kosari
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi every body
I want to know how we can expire cookie.
SetMaxAge(0) expires them if browser closes.but I want to expire them when the browser exists.
Thanks a lot
Arona
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "when the browser exists"? Is that a typo and you mean "exits"? That would be the same as "closes".
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clear cookie value before setting max age 0.
 
arona kosari
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi dears
I read somewhere:
A zero value indicates that the cookies are temporary and will be destroyed once the client closes the browser.
But for example in shopping project,user does not want to close the browser and he log out and login again,and I think with setMaxAge(0) the cookies for previous user exist too.
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

setMaxAge

public void setMaxAge(int expiry)

Sets the maximum age of the cookie in seconds.

A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie's current age.

A negative value means that the cookie is not stored persistently and will be deleted when the Web browser exits. A zero value causes the cookie to be deleted.

Parameters:
expiry - an integer specifying the maximum age of the cookie in seconds; if negative, means the cookie is not stored; if zero, deletes the cookie
 
arona kosari
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dear D Rog,
I set maxAge to zero, but it does not work.
When user purchase what he selected to buy, the maxAge of all cookies will be set to zero.and when another user login and select some goods, his choice will be added to the chioce of previous user and show all of them.
I have still problem with them.
Thanking you in anticipation
Arona
 
Tony Burleson
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition to expiring a cookie, you can also set the value of the cookie to some useless value, say myvalue=cleared. This is only to add a "peace of mind" for management and has no real business value.

If both the expiration and the value are not being set, then that is out of your control and the problem is with the browser not changing as requested.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you only want the cart to be active for one user's login duration, why are you using cookies? Why aren't you using session objects?
 
arona kosari
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Tony,Thanks a lot,I set it's value to empty string too,But it does not work.
Dear Ben,yes,you are right,but it was one of my assignment to work with cookies and it's features.But as you said session is better than cookies.
Regards
Arona
 
William Janssen
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides the session on the server which gives a better solution.
You can handle more users from one browser and maintain state over "log outs" easily by placing the name of the cookies is some kind of namespace.
e.g. item="My Book" will be A5EE62_item="My Book"
where the namespace is based on a sessionid or the users loginname (BAEE64 encoded ofcourse) or some hash code over the login name or....
But be aware of the possible security issues since everything is handled on the client side which can be manipulated by everyone.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when another user login and select some goods, his choice will be added to the chioce of previous user and show all of them.


If you are talking about another user on another browser - that sounds like improper use of servlet instance variables instead of sessions.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic