The problem is that Apache does not put the "Set-Cookie" before the 
"Location" when generating headers.  To fix this, you need to build 
the header yourself.  I've found that this works with Netscape and 
IE, but with IE, the place where you redirect to does not have access 
to the cookie that you just set.  All subsequent pages are able to 
read the cookie... It's a bug in IE.


     my $cookie = Apache::Cookie->new($r,
         -name => "MYCOOKIE",
         -value => "VALUE",
         -path => "/some/cookie/path"
     );

     my %headers = (
         "Location" => "/some/redirect/location",
         "Set-Cookie" => $cookie->as_string
     );
     my $header = "Status: 302 Moved\n";
     for my $h (qw(Set-Cookie Location)) {
         $header .= $h.": ".$headers{$h}."\n";
     }
     $header .= "\n";
     $r->send_cgi_header($header);
     return(REDIRECT);

I think this might also only work for local redirects.  I think I 
tried a remote redirect once and had it not work... I not certain of 
that.

Rob


At 12:30 PM +0000 2/8/01, Harrison wrote:
>Dear All.
>
>I can set a cooke fine using:
>
>$r->content_type('text/html');
>$r->header_out('Set-Cookie' =>$cookie);
>$r->send_http_header;
>
>And i can also send a redirect fine using:
>
>$r->content_type('text/html');
>$r->header_out('Location'=>$the_url);
>return REDIRECT;
>
>BUT!
>
>how do i do both? if i use my redirect code, and add an extra 
>header_out , the cookie is not sent (because i have not called 
>send_http_header ? ).
>
>If i add send_http_header, i see the full sent http_header in my browser.
>
>My idea was to have something like
>
>$r->content_type('text/html');
>$r->header_out('Location'=>$the_url);
>$r->header_out('Set-Cookie' =>$cookie);
>$r->send_http_header;
>return REDIRECT;
>
>
>Which does not work.
>
>Thinking about it whilst typing this email, does header_out have a 
>field where i can set the REDIRECT status?
>
>Thanks in advance,
>
>Richard Harrison.


Robert L. Landrum
Senior Programmer
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"It's working correctly.  It's simply working in contrast to what you have
perceived to be correct."

Reply via email to