Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Setting Cookies First and Redirecting Page

by Anonymous Monk
on Sep 15, 2006 at 18:42 UTC ( [id://573223]=note: print w/replies, xml ) Need Help??


in reply to Re: Setting Cookies First and Redirecting Page
in thread Setting Cookies First and Redirecting Page

I know, but how would I setup the cookies?
  • Comment on Re^2: Setting Cookies First and Redirecting Page

Replies are listed 'Best First'.
Re^3: Setting Cookies First and Redirecting Page
by ptum (Priest) on Sep 15, 2006 at 18:52 UTC

    Looking at the code of redirect() in CGI.pm, it looks to me as though the redirect() header can take a $cookie as an argument:

    sub redirect { my($self,@p) = self_or_default(@_); my($url,$target,$status,$cookie,$nph,@other) = rearrange([[LOCATION,URI,URL],TARGET,STATUS,['COOKIE','COOKIE +S'],NPH],@p); $status = '302 Found' unless defined $status; $url ||= $self->self_url; my(@o); foreach (@other) { tr/\"//d; push(@o,split("=",$_,2)); } unshift(@o, '-Status' => $status, '-Location'=> $url, '-nph' => $nph); unshift(@o,'-Target'=>$target) if $target; unshift(@o,'-Type'=>''); my @unescaped; unshift(@unescaped,'-Cookie'=>$cookie) if $cookie; return $self->header((map {$self->unescapeHTML($_)} @o),@unescaped +); }

    Why not build your cookie, and then pass it to the redirect() header just as you did for the 'normal' header? (I haven't tried this.)

      I am using:
      print $query->redirect(-URL => $url,-COOKIE => [$cookie1,$cookie2]);

      It redirects, but the cookie doesn't get set.

        Works for me:

        #!/usr/bin/perl use CGI qw( :standard ); $cookie = cookie( -name => 'sessionID', -value => 'xyzzy', -expires => '+1h', -path => '/', -domain => '.foo.com', ); print redirect( -url => 'http://login.foo.com', -cookie => $cookie );
        Do you have some other portion of the code outputting header stuff that would interfere? Why do you say it's not working. What client? IE? Firefox?

        -derby

        As I said earlier, I haven't tried it, so I cannot offer any guarantees ... but that is a bit strange. Are you redirecting within the same domain as your cookie? Can you show the code you are using to determine if the cookie is set in the destination script?

        Is it essential that you set the cookies on the first page ... if not, it might be the path of least resistance to set them on the destination page ... ?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-26 04:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found