Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Seeking help to avoid duplicate cookies

by jreades (Friar)
on Jun 21, 2001 at 00:36 UTC ( #90180=note: print w/ replies, xml ) Need Help??


in reply to Seeking help to avoid duplicate cookies

I hate to be an unhelpful jerk, but what you're describing is unlikely at best, and most probably impossible.

Try this JS code:

<html> <head> <script language="JavaScript"> function setCookie() { document.cookies = "foo=bar"; } function getCookies() { window.alert("Cookies: " + document.cookies); } </script> </head> <body> <form> <p align="center"><input type="button" value="Set A Cookie" onClick="s +etCookie();"></p> </form> </body> </html>

No matter how many times you click setCookie there's only that one cookie there. By definition cookies have to have unique names, AFAIK.

It sounds like your code is doing something unexpected in terms of how it sets/reads cookies.

Try posting some code and we can take a look...

And on a final note, if you're setting the cookie via JavaScript and reading via Perl then the error could be quite simple:

  • You read cookies in JavaScript as if they were a single string,
  • but you write to them automagically via a simple assignment
  • so if you're saying document.cookies += cookieNames you're going to get some interesting results (i.e. multiple cookies that, apparently, have the same name)

Try it by changing "=" to "+=" in my code.

HTH


Comment on Re: Seeking help to avoid duplicate cookies
Download Code
Re: Seeking help to avoid duplicate cookies
by Anonymous Monk on Jul 30, 2007 at 05:24 UTC
    Actually HTH, this IS an IE error. it happems when the same cookie name is set from different pages, even in the same folder It seems M$ have broken the cookie code. when reading you always get the last one, or none if the page reading is different from the original one that set it the only way around this is to use a while loop on the cookie in question, expiring it until it no longer exists, then setting it again Paul
Re^2: Seeking help to avoid duplicate cookies
by Burak (Chaplain) on Jul 30, 2007 at 18:04 UTC
    By the way, I wrote a JSAN module for handling cookies from JS: HTTP.Cookies

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://90180]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-10-24 18:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (134 votes), past polls