navwin » Tech Talk » Beyond the Basics » More Cookie Help (Why Doubling?)
Beyond the Basics
Post A Reply Post New Topic More Cookie Help (Why Doubling?) Go to Previous / Newer Topic Back to Topic List Go to Next / Older Topic
Christopher
Moderator
Member Rara Avis
since 1999-08-02
Posts 8296
Purgatorial Incarceration

0 posted 2004-02-16 10:06 PM


Trying to figure out a "good" way to explain this. I'm cool on the setting and retreiving bit, but having some problems clearing the cookies... well, kind of. I seem to be able to clear them fine, but they also seem to be doubling - I end up with

owner@www.egowhores[1].txt

and

owner@egowhores[1].txt

which the program appears to be reading as two separate cookies. The thing is, I have no idea HOW I'm creating two sets of cookies.

Needless to say, this is causing a bit of a problem with clearing them.

Any help would be appreciated.

And here's the cookie-call for what it's worth:




sub cookies {
    my $action = $_[0];# action to perform = set, get, clear
    my (@cookies, $name, $value, $key);
    if ($action =~ /get/i) {
        # GET cookies
        foreach (split(/; /, $ENV{'HTTP_COOKIE'})) {
            s/\+/ /g;
            s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
            ($name, $value) = split(/=/,$_,2);
            if ($name eq "egowhores") {
                @cookies = split(/\|/, $value);
                $cookie{aID} = $cookies[0];
                $cookie{aPassword} = $cookies[1];
            } else {
                $cookie{$name} = $value;
            }
        }
    } elsif ($action =~ /set/i) {
        # SET cookies
        $value = "$cookie{aID}\|$cookie{aPassword}";
        $Expires = "Wed, 23-Feb-2005 00:00:00 GMT";
        print qq~Set-Cookie: egowhores=$value;expires=$Expires;path=/;\n~;
    } else {
        $value = "";
        $Expires = "Wed, 23-Feb-2005 00:00:00 GMT";
        print qq~Set-Cookie: egowhores=$value;expires=$Expires;path=/;\n~;
        undef %cookie;
    }
}

© Copyright 2004 C.G. Ward - All Rights Reserved
Ron
Administrator
Member Rara Avis
since 1999-05-19
Posts 8669
Michigan, US
1 posted 2004-02-17 06:37 AM


quote:
I end up with

owner@www.egowhores[1].txt

and

owner@egowhores[1].txt

which the program appears to be reading as two separate cookies.

I'm guessing those are coming from outside your script, Chris? From examining the disk for cookies?

Bottom line is that they ARE two separate cookies, or at least should be, depending on your server configuration at the Apache level. If you read the Help files I've written here for cookies, one of the warnings I issue is to never use our www.piptalk.com domain, because it is NOT the same as piptalk.com as far as cookies are concerned. All of our URLs in the forums very carefully avoid the www prefix for that very reason. Cookies are domain dependent (more or less).

Pick one domain and stick to it. Your program should never run on the other.


quote:
I end up with

owner@www.egowhores[1].txt

and

owner@egowhores[1].txt

which the program appears to be reading as two separate cookies.

I'm guessing those are coming from outside your script, Chris? From examining the disk for cookies?

Bottom line is that they ARE two separate cookies, or at least should be, depending on your server configuration at the Apache level. If you read the Help files I've written here for cookies, one of the warnings I issue is to never use our www.piptalk.com domain, because it is NOT the same as piptalk.com as far as cookies are concerned. All of our URLs in the forums very carefully avoid the www prefix for that very reason. Cookies are domain dependent (more or less).

Pick one domain and stick to it. Your program should never run on the other.



Christopher
Moderator
Member Rara Avis
since 1999-08-02
Posts 8296
Purgatorial Incarceration
2 posted 2004-02-17 01:06 PM


see, it even doubled your post, Ron.

I understand what you're saying... with the exception of HOW i'm arriving at this duplicate. I don't believe (though I will double-check tonight) that i'm entering the page differently...

Thank you for your response.


Christopher
Moderator
Member Rara Avis
since 1999-08-02
Posts 8296
Purgatorial Incarceration
3 posted 2004-02-17 01:07 PM


And yes, those are coming from examining my cookies - they are the file handles in my "cookies" section on the hard disk.
Christopher
Moderator
Member Rara Avis
since 1999-08-02
Posts 8296
Purgatorial Incarceration
4 posted 2004-02-17 10:35 PM


Now that I'm home and can look at what was happening - I understand fully... is there no way then to cover both eventualities? i'm guessing not, since they will be seen as cookies from two different sites.

bummer. thanks again Ron.

C

Ron
Administrator
Member Rara Avis
since 1999-05-19
Posts 8669
Michigan, US
5 posted 2004-02-18 08:10 PM


quote:
... is there no way then to cover both eventualities?


Actually, there is, at least two that I know (now).

http://poetry-web.com/

Click on the above link and then look at your Address/Location bar. This is the result of an Apache configuration command (see RedirectPermanent ) placed in httpd.conf on the server. It is activated way before any page or Perl code can be called, making it impossible to create cookies for the base domain … 'cause ya can't get there from here (or any where else).

The benefits to this solution go well beyond cookies. Most of the search engines, and especially Google, count links to your web site as "votes" from outside parties. If you have 1,000 links to your site and I have only 500 to mine, Google figures your site is "better" than my site. All other things being equal (though they never are), your site will rank much higher in a search than will mine. The problem arises when your 1,000 inbound links are split and my 500 aren't. You have 500 links to domain.com, 500 links to www.domain..com, thus making each equivalent to my 500 links. Your "votes" have been diluted by inconsistent linking, so you don't get all the benefits from them that you could.

When Google encounters a RedirectPermanent (often called a 301), it realizes the two domains should be considered the same and combines all their votes.

The disadvantage to this solution is that it's pretty low level and won't be available to everyone. If you're on a shared server, the only way to implement it is to talk your hosting company into making the changes for you. Frankly, most hosting companies won't know enough about Apache to even know what you want.

So, here's an alternative solution that should work for you. I haven't tested it, so would appreciate your feedback on the results.

Change every instance of this:

print qq~Set-Cookie: egowhores=$value;expires=$Expires;path=/;\n~;

to this:

print qq~Set-Cookie: egowhores=$value;expires=$Expires;domain=. egowhores.com;path=/;\n~;

Please note that .egowhores.com has TWO periods, and could probably be read as *.egowhores.com to be more intuitive. This "should" make your cookies work across all subdomains, including www. Let me know if it does?



Christopher
Moderator
Member Rara Avis
since 1999-08-02
Posts 8296
Purgatorial Incarceration
6 posted 2004-02-18 09:30 PM


Of course I will!
Christopher
Moderator
Member Rara Avis
since 1999-08-02
Posts 8296
Purgatorial Incarceration
7 posted 2004-02-19 10:05 PM


Worked beautifully.

I did have to go back and remove the space between the period prior to "egowhores", however. I'd noticed it earlier when i first looked at this, but forgot until it didn't work.

I tried logging in and out with sans and with www.,  worked fine, mixed it up a both and seems to be working great. It just changes the number in brackets, ie: owner@egowhores.com[1], but isn't creating a separate cookie.

Sweetness from the smart man.  

Post A Reply Post New Topic ⇧ top of page ⇧ Go to Previous / Newer Topic Back to Topic List Go to Next / Older Topic
All times are ET (US). All dates are in Year-Month-Day format.
navwin » Tech Talk » Beyond the Basics » More Cookie Help (Why Doubling?)

Passions in Poetry | pipTalk Home Page | Main Poetry Forums | 100 Best Poems

How to Join | Member's Area / Help | Private Library | Search | Contact Us | Login
Discussion | Tech Talk | Archives | Sanctuary