navwin » Tech Talk » Beyond the Basics » New Cookie Issue
Beyond the Basics
Post A Reply Post New Topic New Cookie Issue 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-09 01:03 AM



For some reason, I am having problem with cookies again. I thought I had them beat some time ago and can't help but feeling I'm missing something rather simple (isn't that usually the case?).

They seem to be writing fine, but my call to get them doesn't appear to be operating correctly - though looking at it, I can't for the life of me determine why. If you could help steer me in the right direction, it would be much appreciated.

Set cookies: http://egowhores.com/linkage
Name: user
Password: password

Then close out that screen and click: http://egowhores.com/cgi-bin/pl/plink.pl

The action performed by this link is:

if (! $action) {

cookies("get");

header();
print qq~Info from env content: <b>$ENV{'HTTP_COOKIE'}</b><br><br>~;
print qq~Line 1:<b>$cookies[0]</b><br>Line 2:<b>$cookies[1]</b>~;

}#End if no action clause




The subroutine for cookies is:

# cookies("get / set / clear");
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 = "Sun, 31-Dec-2000 00:00:00 GMT";
        print qq~Set-Cookie: egowhores=$value;expires=$Expires;path=/;\n~;
        undef %cookie;
    }
}#end SR cookies

© Copyright 2004 C.G. Ward - All Rights Reserved
Christopher
Moderator
Member Rara Avis
since 1999-08-02
Posts 8296
Purgatorial Incarceration
1 posted 2004-02-09 01:06 AM


By the way - the cookie sub-routine should look familiar, Ron, as it's almost exactly what you gave me a year and a half ago (had it working then too).
Mysteria
Deputy Moderator 10 ToursDeputy Moderator 10 ToursDeputy Moderator 10 ToursDeputy Moderator 10 ToursDeputy Moderator 1 TourDeputy Moderator 1 TourDeputy Moderator 1 Tour
Member Laureate
since 2001-03-07
Posts 18328
British Columbia, Canada
2 posted 2004-02-09 01:30 AM


After reading that I need a coffee and of course, a cookie!
Ron
Administrator
Member Rara Avis
since 1999-05-19
Posts 8669
Michigan, US
3 posted 2004-02-09 01:41 AM


I'll take a closer look at the code tomorrow, if necessary, when I'm not quite so brain-dead. I doubt it will be necessary, though, as I doubt there are any problems with the code.

If memory serves, Chris, you initially ran into the same problem last time? Put both scripts in the same directory and I suspect it will magically start working.  

Ron
Administrator
Member Rara Avis
since 1999-05-19
Posts 8669
Michigan, US
4 posted 2004-02-09 01:51 AM


Scratch that. If you can print the ENV variable, it's not a path problem.

I'll be back …

Ron
Administrator
Member Rara Avis
since 1999-05-19
Posts 8669
Michigan, US
5 posted 2004-02-09 02:04 AM


Okay, here's your problem, Chris.

In the cookies function you are declaring the scalar array @cookies locally (with my), but then you try printing it in the calling routine as if it were global. That won't work because the array was destroyed the minute you left the routine where it was declared.

Try printing out the hash variables, $cookie{aID} and $cookie{aPassword}, instead. The hash called cookie "should" be global.

Midnitesun
Deputy Moderator 1 Tour
Member Empyrean
since 2001-05-18
Posts 28647
Gaia
6 posted 2004-02-09 09:40 AM


Wow, what a lesson in code!
All I want is a simple oatmeal raisin cookie
with gourmet java.
BTW Ron, I will be changing my email addy (again!) in two weeks. Should I be deleting all my cookies before the move, and eliminate access to the DM forums?  When I reconnect the PC will end up in my daughter's bedroom, and she doesn't need to have adult/DM access. Thanks! Midnitesun
(unplugging this on Feb 11)  

Christopher
Moderator
Member Rara Avis
since 1999-08-02
Posts 8296
Purgatorial Incarceration
7 posted 2004-02-09 12:43 PM


I even looked at that too, Ron, but didn't even connect that by declaring the array as local [my], that it would extend to the variables broken out as well... which makes complete sense in retrospect.

Thank you Ron, as always, your help is not only help, but educational. Much appreciated.

Sharon - sounds good, pass some my way???

MidniteSun: If you go to the member's section at the top of the page, there is a place where you can manipulate your cookies to "remember you". If you disable that, you can later log in and log out without having to worry about your daughter having access to what you feel is inappropriate material.  

C

Susan Caldwell
Member Rara Avis
since 2002-12-27
Posts 8348
Florida
8 posted 2004-02-09 02:36 PM


oh my.  

zing, right over my head.

and you know what?

I like it that way.

geez.

Make mine chocolate chip.

Obscurity
Member
since 2003-12-04
Posts 153
In A Melancholic Dream
9 posted 2004-02-11 08:49 AM


Perl, the only language that looks the same before and after it goes through the RSA Algorithm :P
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 » New Cookie Issue

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