Well, I ran into this problem a while back... I solved it by baking my 
cookies and sening a Refresh: header to the browser.  The format is the 
same as the more popularly used META tag. (eg "Refresh: $time;url=$url")
For example, to immediately redirect from /foo to /bar while setting a 
cookie, I'd do something like:

$cookie->bake;
$r->header_out("Refresh"=>"0;url=bar");
$r->send_http_header;
return OK;

VERY IMPORTANT: Make sure you type url= in lowercase.  It's usually case 
sensitive.

  Issac

Axel Andersson wrote:

>Hello,
>I'm having trouble with both setting a cookie and redirecting the user to
>another page at the same time. It would appear the cookie is only sent
>when a normal header is sent by server.
>
>If I do the following (having baked the cookie first), where $r is the
>Apache->request() object:
>
>       $r->content_type("text/html; charset=iso-8859-1");
>       $r->send_http_header();
>
>I get this header:
>
>  Connection: close
>  Date: Tue, 12 Mar 2002 10:39:05 GMT
>  Server: Apache/1.3.23 (Unix) mod_perl/1.26
>  Content-Type: text/html; charset=iso-8859-1
>  Client-Date: Tue, 12 Mar 2002 10:39:05 GMT
>  Client-Response-Num: 1
>  Client-Transfer-Encoding: chunked
>  Set-Cookie: user=12::7c786c222596437b; domain=animanga.nu; path=/;
>expires=Wed, 
>  12-Mar-2003 10:39:05 GMT
>
>Very nice and all, with cookie set. However, doing:
>
>       $r->method_number(M_GET);
>       $r->method("GET");
>       $r->headers_in->unset("Content-length");
>       $r->headers_out->add("Location" => "/users.pl");
>       $r->status(REDIRECT);
>       $r->send_http_header();
>
>Which I gather is the normal way to redirect a user, I get this header:
>
>  Connection: close
>  Date: Tue, 12 Mar 2002 10:38:36 GMT
>  Server: Apache/1.3.23 (Unix) mod_perl/1.26
>  Content-Type: text/html; charset=iso-8859-1
>  Client-Date: Tue, 12 Mar 2002 10:38:36 GMT
>  Client-Response-Num: 1
>  Client-Transfer-Encoding: chunked
>
>Right, no Set-cookie there. So what's up? How do I redirect a browser,
>and set a cookie at the same time?
>
>Thanks in advance,
>Axel Andersson
>



Reply via email to