Jim Winstead wrote:
> 
> On Apr 08, Zeqing Xia wrote:
> > Hi,
> >
> > I'm having a problem with setting the cookie in a REDIRECT. Basically,
> > I'm doing this in a handler:
> >
> >     $r->headers_out->add('Set-Cookie' => $cookie);
> >     $r->headers_out->add('Location' => $location);
> >     return REDIRECT;
> >
> > The $location is hit but the cookie is missing when I debug the handler
> > for $location.
> >
> > I have tried various remedies, such as no_cache(),
> > unset('Content-length'), etc. But nothing seems have effect.
> >
> > Can anyone point out what is the problem? Thanks so much.
> 
> This is a misfeature of some browsers. (Particular versions of
> Internet Explorer, if I remember correctly.)
> 
> Some people have reported success with some browsers depending on
> the order the headers appear, but the most bullet-proof solution
> is to do a redirect with a header or meta-tag refresh instead of
> an redirect. (Which is definitely not as user-friendly, but works
> for all cookie-enabled browsers that I've come across.)
> 
> So you'd want to do something like:
> 
>   $r->headers_out->add('Set-Cookie' => $cookie);
>   $r->headers_out->add('Refresh' => "0; url=$location");
>   $r->print("Sending you <a href='$location'>here</a>.");
>   return OK;
> 
> Jim

You could also put the cookie info in the URL you redirect to (as a
query string), and make your handler look for it there if the cookie is
missing.

- Perrin

Reply via email to