Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Cookies with CGI::Application

by Belgarion (Chaplain)
on May 16, 2004 at 05:46 UTC ( [id://353737]=note: print w/replies, xml ) Need Help??


in reply to Cookies with CGI::Application

I think we're going to need a bit more information. If this was my code I would telnet into the web server and see what information is being sent back in response to a GET request. The "Set-Cookie" lines should be present. The question then becomes, what is in those lines. Also, in the above example you say that return_cookies returns:

SET per_page=12; path=/; expires=1h keyword_not=cat; path=/; expires=1 +h keyword_or=tree; path=/; expires=1h keyword_combined=tree%20NOT%20c +at; path=/; expires=1h

Is this a string it's returning? Or an array of strings? It would be really helpful if you could provide a Data::Dumper output of the return_cookies function. I don't belive the literal SET should be present in the cookie output.

Are you using the CGI::Cookie module to handle your cookies, or did you roll your own?

Replies are listed 'Best First'.
Re: Re: Cookies with CGI::Application
by Anonymous Monk on May 16, 2004 at 07:45 UTC

    I have this routine which I use through the app to make cookies for certain things

    sub bake { my $cookie = shift; my @args = @_; use CGI; my $query = new CGI; # Make a new cookie my $new_cookie = $query->cookie(@args); # Get the cookies already baked my $cookies = $cookie->param('cookies'); my @new_cookies; push(@new_cookies, $new_cookie); push(@new_cookies, @$cookies) if $cookies; $cookie->param('cookies', ¥@new_cookies); }

    Then, to retrieve the cookies before I out put:

    sub return_cookies { my $cookie = shift ; my $cookies = $cookie->param('cookies'); $cookie->debug("SET @$cookies") if $cookies; return @$cookies if $cookies; }

    The strange thing is of course, that this particular part worked fine for a day. I did not touch it, but made several changed to the main app. This leads me to believe it is not a problem with the cookie setting/retreiving function, but someplace else. And since &return_cookies returns exactly what I expect, I am totally lost.

    I just discovered something strange. I am using CGI::Application so I have various run modes:

    sub top { my $app = shift; # Reset the cookies $app->cookie->bake(-name=>'site', -value=>$app->query->param('site +'), -expires=>'1h'); $app->cookie->bake(-name=>'keyword_or', -value=>'', -expires=>'-1h +'); $app->param('template', $app->get_template('top.html')); return ($app->output); } sub results { my $app = shift; # Do stuff to the keyword &manage_keyword($app) if ($app->query->param('do_search')); return ($app->output); } sub manage_keyword { my $app = shift; my $keyword_or = $app->query->param('keyword_or'); $keyword_combined ||= $app->query->cookie('keyword_or'); .... $app->cookie->bake(-name=>'keyword_or', -value=>"$keyword_or") if +$keyword_or; ..... }

    For some reason, even though the run_mode is results, the

    $app->cookie->bake(-name=>'keyword_or', -value=>'', -expires=>'-1h');

    in run_mode "top" seems to be deleting my cookie. If I comment that out, it works fine. Why the hang is it even paying attention to "top" ?

      &manage_keyword($app)

      This is just a newbie doubt:

      Is it correct to call a sub in this way?

      I see that &manage_keyword only gets its usual first parameter.

      I have also noticed that you use several variables with very similar names. Does it help?

      .{\('v')/}
      _`(___)' __________________________

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2025-07-18 11:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.