You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by gerard uolaquetalestem <vi...@mixmail.com> on 2003/08/09 16:01:56 UTC

$r->headers_out Location and Set-Cookie

I have the next problem, i am in page A that <form> points to page B, that is 
a modperl2 handler.
This handler makes a job and decides to send a cookie to the browser, and 
after to redirect to the same page A who is ready to catch the cookie.

Then the problem is that if i put the two headers, i don't have the cookie 
posted, but if i comment the Location header, then i stay at perl handler 
location, and if i go manually to page A then i see that the cookie is posted.

So why these two headers doesn't respect themselves?

Resuming
$r->headers_out->{'Set-Cookie'} = $cookie;
$r->headers_out->{'Location'} = $url;
Redirects the page to $url but cookie is not seen by browser

$r->headers_out->{'Set-Cookie'} = $cookie;
#$r->headers_out->{'Location'} = $url;
Location is the perl handler 'localhost/pageB/' (perl handler), if you then go 
to localhost/pageA (or simply click BACK button) then the browser DO see 
the cookie!

Any idea?


-----
Un nuevo buscador m�s r�pido, eficaz y sencillo http://www.plaf.com
Ya.com ADSL Home 24h, M�dem + Alta + 1 mes Gratis http://acceso.ya.com/adslhome24h/

Re: $r->headers_out Location and Set-Cookie

Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> Chris Faust wrote:
> 
>> I haven't had any problems setting a cookie and redirecting on MP2 by 
>> using
>> the below
>>
>>   $r->err_headers_out->add('Set-Cookie' => $packed_cookie);
>>   $r->header_out('Location' => $url);
>>   $r->status(REDIRECT);
>>   $r->send_http_header;
> 
> 
> That's when you use Apache::compat, doing the mp1 syntax. In mp2-speak 
> that would be:
> 
>   $r->err_headers_out->add('Set-Cookie' => $packed_cookie);
>   $r->headers_out->set('Location' => $url);
>   $r->status(REDIRECT);
> 
> notice that you don't need to call $r->send_http_header, it doesn't 
> exist in mp2.

I've added this to the new mp2 cooking chapter:
http://perl.apache.org/docs/2.0/user/coding/cooking.html#Sending_Cookies_in_REDIRECT_Response

it would be useful to port interesting entries from
http://perl.apache.org/docs/1.0/guide/snippets.html
and may be add new ones...

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: $r->headers_out Location and Set-Cookie

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> That's when you use Apache::compat, doing the mp1 syntax. In mp2-speak 
> that would be:
> 
>   $r->err_headers_out->add('Set-Cookie' => $packed_cookie);
>   $r->headers_out->set('Location' => $url);
>   $r->status(REDIRECT);
> 
> notice that you don't need to call $r->send_http_header, it doesn't 
> exist in mp2.

not to mention it's entirely unnecessary (and undesirable) to send headers 
on error responses such as redirects.

and you should never set $r->status from a handler - for Registry scripts 
it's ok, since we use it as a hack to get around some things, but handlers 
should never manipulate the value of $r->status.

--Geoff


Re: $r->headers_out Location and Set-Cookie

Posted by Chris Faust <cf...@doyougot.com>.
Ahh, didn't know that..  Thanks Stas!

-Chris

----- Original Message ----- 
From: "Stas Bekman" <st...@stason.org>
To: "Chris Faust" <cf...@doyougot.com>
Cc: <vi...@mixmail.com>; <mo...@perl.apache.org>
Sent: Sunday, August 10, 2003 2:37 PM
Subject: Re: $r->headers_out Location and Set-Cookie


> Chris Faust wrote:
> > I haven't had any problems setting a cookie and redirecting on MP2 by
using
> > the below
> >
> >   $r->err_headers_out->add('Set-Cookie' => $packed_cookie);
> >   $r->header_out('Location' => $url);
> >   $r->status(REDIRECT);
> >   $r->send_http_header;
>
> That's when you use Apache::compat, doing the mp1 syntax. In mp2-speak
that
> would be:
>
>    $r->err_headers_out->add('Set-Cookie' => $packed_cookie);
>    $r->headers_out->set('Location' => $url);
>    $r->status(REDIRECT);
>
> notice that you don't need to call $r->send_http_header, it doesn't exist
in mp2.
>
> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com
>



Re: $r->headers_out Location and Set-Cookie

Posted by Stas Bekman <st...@stason.org>.
Chris Faust wrote:
> I haven't had any problems setting a cookie and redirecting on MP2 by using
> the below
> 
>   $r->err_headers_out->add('Set-Cookie' => $packed_cookie);
>   $r->header_out('Location' => $url);
>   $r->status(REDIRECT);
>   $r->send_http_header;

That's when you use Apache::compat, doing the mp1 syntax. In mp2-speak that 
would be:

   $r->err_headers_out->add('Set-Cookie' => $packed_cookie);
   $r->headers_out->set('Location' => $url);
   $r->status(REDIRECT);

notice that you don't need to call $r->send_http_header, it doesn't exist in mp2.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: $r->headers_out Location and Set-Cookie

Posted by Chris Faust <cf...@doyougot.com>.
I haven't had any problems setting a cookie and redirecting on MP2 by using
the below

  $r->err_headers_out->add('Set-Cookie' => $packed_cookie);
  $r->header_out('Location' => $url);
  $r->status(REDIRECT);
  $r->send_http_header;

-Chris


----- Original Message ----- 
From: "gerard uolaquetalestem " <vi...@mixmail.com>
To: <mo...@perl.apache.org>
Sent: Saturday, August 09, 2003 10:01 AM
Subject: $r->headers_out Location and Set-Cookie



I have the next problem, i am in page A that <form> points to page B, that
is
a modperl2 handler.
This handler makes a job and decides to send a cookie to the browser, and
after to redirect to the same page A who is ready to catch the cookie.

Then the problem is that if i put the two headers, i don't have the cookie
posted, but if i comment the Location header, then i stay at perl handler
location, and if i go manually to page A then i see that the cookie is
posted.

So why these two headers doesn't respect themselves?

Resuming
$r->headers_out->{'Set-Cookie'} = $cookie;
$r->headers_out->{'Location'} = $url;
Redirects the page to $url but cookie is not seen by browser

$r->headers_out->{'Set-Cookie'} = $cookie;
#$r->headers_out->{'Location'} = $url;
Location is the perl handler 'localhost/pageB/' (perl handler), if you then
go
to localhost/pageA (or simply click BACK button) then the browser DO see
the cookie!

Any idea?


-----
Un nuevo buscador mas rapido, eficaz y sencillo http://www.plaf.com
Ya.com ADSL Home 24h, Modem + Alta + 1 mes Gratis
http://acceso.ya.com/adslhome24h/



Re: $r->headers_out Location and Set-Cookie

Posted by Matt Sergeant <ma...@sergeant.org>.
On Saturday, Aug 9, 2003, at 15:26 Europe/London, Nick Tonkin wrote:

> On Sat, 9 Aug 2003, gerard uolaquetalestem  wrote:
>
>> I have the next problem, i am in page A that <form> points to page B, 
>> that is
>> a modperl2 handler.
>> This handler makes a job and decides to send a cookie to the browser, 
>> and
>> after to redirect to the same page A who is ready to catch the cookie.
>

> Yep. You need $r->err_headers_out->{'Location'} and you could change 
> to $r->err_headers_out->{'Set-Cookie'} too.

Even that doesn't work. You need to do a Refresh, because that's the 
only way the browser will register the cookie - Set-Cookie + Location 
is not compatible (generally - some browsers will accept the cookie).

Matt.


Re: $r->headers_out Location and Set-Cookie

Posted by Nick Tonkin <ni...@tonkinresolutions.com>.
On Sat, 9 Aug 2003, gerard uolaquetalestem  wrote:

>
> I have the next problem, i am in page A that <form> points to page B, that is
> a modperl2 handler.
> This handler makes a job and decides to send a cookie to the browser, and
> after to redirect to the same page A who is ready to catch the cookie.
>
> Then the problem is that if i put the two headers, i don't have the cookie
> posted, but if i comment the Location header, then i stay at perl handler
> location, and if i go manually to page A then i see that the cookie is posted.
>
> So why these two headers doesn't respect themselves?
>
> Resuming
> $r->headers_out->{'Set-Cookie'} = $cookie;
> $r->headers_out->{'Location'} = $url;
> Redirects the page to $url but cookie is not seen by browser
>
> $r->headers_out->{'Set-Cookie'} = $cookie;
> #$r->headers_out->{'Location'} = $url;
> Location is the perl handler 'localhost/pageB/' (perl handler), if you then go
> to localhost/pageA (or simply click BACK button) then the browser DO see
> the cookie!
>
> Any idea?


Yep. You need $r->err_headers_out->{'Location'} and you could change to $r->err_headers_out->{'Set-Cookie'} too.


- nick

-- 

~~~~~~~~~~~~~~~~~~~~
Nick Tonkin   {|8^)>