in reply to annoying duplicate cookies

Unfortunately it is all too possible to have 2 cookies with an identical name. I'm not the only one that I've heard of with this problem. I do believe the problem is related to how the browser handles the path, but when you read a cookie, you have no control over that (unless you can correct me on this).

I already posted the code I use to reed the cookie. I simply use $ENV{'HTTP_COOKIE'}. That returns a string containing all the cookies for that site on the user's browser. Also, there is no case problem or errant character with the name. I wish it were that somple.

I am aware that a user can log in from more than one PC, but my site only keeps the most recent cookie image from that user as a snap shot, so I don't store a cookie from each PC. Also note that for the cookie I use, I set the expiration to 1 year, so the cookie hangs around for a lot longer than many cookies do. If you use cookies, you may be having this problem, but aren't aware of it either because your expiration is so short, or an old duplicate cookie won't cause problems in your code.

The code to write the cookie is...

. . $co = new CGI; . . . $newunp = join('|',@batch); $ck_unp = $co->cookie( -name=>'unp', -value=>$newunp, -expires=>'+365d' ); print $co->header(-cookie=>$ck_unp); . .

Again, thanks for any help.

Replies are listed 'Best First'.
Re: Re: annoying duplicate cookies
by eejack (Hermit) on Jun 24, 2001 at 22:50 UTC
    Nardo brings up a good point about the domain portion of the cookie...one I haven't run into because I redirect .domain.com to www.domain.com on all my servers.

    As far as I can determine you cannot access the path or domain portion of the browsers cookie, to set yes, to read no.

    Assuming it is the domain portion that might be a problem, you could force everyone into either www.domain.com or domain.com - that should *eventually* solve the problem.

    But even if you go through and expire all the cookies of folks who log on, and rewrite them in a very exact way, it still might take a year to eliminate them all.

    You might want to add a path and domain to where you are setting the cookies as a start (will not solve the problem of people with duplicates...), that way the browser cannot make it's own determination of those items.

    But as far as solving it completely I cannot be of assistance.

    EEjack