Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Setting Cookies First and Redirecting Page

by ptum (Priest)
on Sep 15, 2006 at 18:24 UTC ( [id://573217]=note: print w/replies, xml ) Need Help??


in reply to Setting Cookies First and Redirecting Page

As per the docs, a 'normal' header and a redirect header are mutually exclusive:

"The redirect() function redirects the browser to a different URL. If you use redirection like this, you should not print out a header as well."


No good deed goes unpunished. -- (attributed to) Oscar Wilde
  • Comment on Re: Setting Cookies First and Redirecting Page

Replies are listed 'Best First'.
Re^2: Setting Cookies First and Redirecting Page
by Anonymous Monk on Sep 15, 2006 at 18:42 UTC
    I know, but how would I setup the cookies?

      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.

Log In?
Username:
Password:

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

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

    No recent polls found