Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

CGI::Application - Setting a Cookie and Redirecting

by joshua (Pilgrim)
on Aug 26, 2002 at 01:59 UTC ( [id://192740]=perlquestion: print w/replies, xml ) Need Help??

joshua has asked for the wisdom of the Perl Monks concerning the following question:

I've been using CGI::Application for some programs recently and was wondering if there was a simple way to set a cookie and redirect at the same time.

I tried the following code in a run-mode; it redirects, but it doesn't seem to set the cookie...

$self->header_type('redirect'); $self->header_props( -cookie=> $q->cookie( -name=>$account, -value=>$new_session_id ) , -uri=>"http://x.com/cgi-bin/admin.cgi?mode=admin&account=$accoun +t" );

 

I'm currently using the following code, but would rather not resort to using HTML...

$self->header_props( -cookie=> $q->cookie( -name=>$account, -value=>$new_session_id ) ); my $output = $q->start_html( -head=>$q->meta({-http_equiv=>'Refresh',-content=>"0; URL=http://x +.com/cgi-bin/admin.cgi?mode=admin&account=$account"}) ); $output .= $q->a({-href=>"http://x.com/cgi-bin/admin.cgi?mode=admin&ac +count=$account"},"Proceed to admin >>"); $output .= $q->end_html(); return $output;
Thanks!
Joshua

Replies are listed 'Best First'.
Re: CGI::Application - Setting a Cookie and Redirecting
by rob_au (Abbot) on Aug 26, 2002 at 02:05 UTC
    Your usage of the CGI::Application framework is correct. I would however be adding a path to the cookie object - From some of my code:

    $self->header_props( -cookie => $cgi->cookie( -name => 'Application', -path => '/', -value => $session{ '_session_id' } ), -uri => $uri ); $self->header_type('redirect');

    Also too, you may want to confirm the return HTTP headers from your application to ensure that indeed the cookie is being set and that the value therein is as intended.

     

Re: CGI::Application - Setting a Cookie and Redirecting
by spartacus9 (Beadle) on Aug 28, 2002 at 03:50 UTC
    I have had a similar problem before and I seem to recall it had something to do with setting both the domain and path attributes of the cookie. CGI.pm actually tried to set the cookie, but for some reason when you are setting the cookie inside a redirect, the browser requires the path and domain attributes. The other difference I noticed is that I used the "location" attribute to specify the redirect destination and you have used the "uri" attribute. Hope this helps.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 13:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found