On Thu, 8 Feb 2001, Harrison wrote:

> Date: Thu, 8 Feb 2001 12:30:31 -0000
> From: Harrison <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Send a cookie, AND a redirect ? 
> 
> 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.
> 

I've had good luck using Apache::Cookie.  Like so:

sub handler {
    my $apr = shift;
    my $cookie = Apache::Cookie->new($apr,
                            -name    => 'foo',
                            -value   => 'bar',
                            -expires => '+30m',
                            -domain  => 'baz.com',
                            -path    => '/');
    $cookie->bake;

    $apr->method_number(M_GET);
    $apr->method('GET');
    $apr->headers_in->unset('Content-length');
    $apr->headers_out->add('Location' => 'index.html');
    $apr->status(REDIRECT);
    $apr->send_http_header;
    return DONE;
}

ky

Reply via email to