Mailing List Archive

Cookie problem under mod_perl :( . Need help.
Hi!

Setting Cookie via headers_out() function does not work :(
see the code:
==
..
use Apache;
..
sub handler {
my( %form, $ua, $r, $key, $value);
$r = Apache->request();

my $headers_out = $r->headers_out;
my $headers_in = $r->headers_in;
my %h = $r->headers_in();
$headers_out->{Cookie} = 'SESSION=1A91933A; domain=acme.com';
$r->send_http_header('text/html');
print '<html><head></head><body><h2>Data:</h2>';
print '<b>Cookie: </b>' . $headers_in->{Cookie} . '<br>';
print '<h3>Headers:</h3><pre>';
while(($key, $value) = each(%h)) {
print "$key -> $h{$key} \n";
}
print '</pre>';
print '</body></html>';

} # end of handler.
..
==
but cookie works when I replace $r->send_http_header('text/html') with
print "Content-Type: text/html\n\n";
print "Set-Cookie: lala=foo";

What's the problem?

Best regards,
******************************************************
Vlad A. Safronov vlads@comptek.ru
Re: Cookie problem under mod_perl :( . Need help. [ In reply to ]
At 20:06 24/02/2000 +0300, Vlad Safronov wrote:
>sub handler {
> my( %form, $ua, $r, $key, $value);
> $r = Apache->request();
>
> my $headers_out = $r->headers_out;
> my $headers_in = $r->headers_in;
> my %h = $r->headers_in();
> $headers_out->{Cookie} = 'SESSION=1A91933A; domain=acme.com';

As per Stas's request that we post even when unsure (actually I think if I
had slept last night it'd be clearer :).

I think you shouldn't assign $r->headers_out to a value and use it like
that. Try either:

$r->header_out('Set-Cookie', 'foocookiecontent'); # notice it's singular
# or
my $h_out = $r->headers_out; # plural here
$h_out->add('Set-Cookie', 'foocookiecontent');
# or do without the assignment
$r->headers_out->add('Set-Cookie', 'foocookiecontent');

Similarly (though that's not affecting your program) you're assigning
headers_in to a variable which you're not using afterwards.

hth



.Robin
Earth is a beta site.
Re: Cookie problem under mod_perl :( . Need help. [ In reply to ]
Ok. Trying this code:
==
$r = Apache->request();
my $headers_out = $r->headers_out;

$headers_out->add('Set-Cookie', 'SESSION=1A91933A; domain=abe;');
$headers_out->add('Set-Cookie', 'fefe=jkwq;');
$r->send_http_header();
..
==
Cookie 'fefe=jkwq' has been sent.
Cookie 'SESSION=1A91933A; domain=abe;' has been lost, disappeared, stuck
somewhere..

What's the problem now? I got right hash ref, I used ->add() method ..
but cookie hadn't been added! Why do we need this hash ref. that
$r->headers_out()
returns???

/ Vlad.

Robin Berjon wrote:
>
> At 20:06 24/02/2000 +0300, Vlad Safronov wrote:
> >sub handler {
> > my( %form, $ua, $r, $key, $value);
> > $r = Apache->request();
> >
> > my $headers_out = $r->headers_out;
> > my $headers_in = $r->headers_in;
> > my %h = $r->headers_in();
> > $headers_out->{Cookie} = 'SESSION=1A91933A; domain=acme.com';
>
> As per Stas's request that we post even when unsure (actually I think if I
> had slept last night it'd be clearer :).
>
> I think you shouldn't assign $r->headers_out to a value and use it like
> that. Try either:
>
> $r->header_out('Set-Cookie', 'foocookiecontent'); # notice it's singular
> # or
> my $h_out = $r->headers_out; # plural here
> $h_out->add('Set-Cookie', 'foocookiecontent');
> # or do without the assignment
> $r->headers_out->add('Set-Cookie', 'foocookiecontent');
>
> Similarly (though that's not affecting your program) you're assigning
> headers_in to a variable which you're not using afterwards.
>
> hth
>
> .Robin
> Earth is a beta site.

--

Best regards,
******************************************************
Vlad A. Safronov vlads@comptek.ru
CompTek Intl. www.yandex.ru, www.comptek.ru
Tel.: +7(095)785-2525, ext. 586
RE: Cookie problem under mod_perl :( . Need help. [ In reply to ]
according to RFC 2109, a set-cookie domain must always start with a dot...
it also says that the domain has to match the request host...

thus, try something like
$headers_out->add('Set-Cookie', 'SESSION=1A91933A; domain=.comptek.ru;');
instead...

HTH

--Geoff

> -----Original Message-----
> From: Vlad Safronov [mailto:vlads@comptek.ru]
> Sent: Friday, February 25, 2000 5:07 AM
> To: Robin Berjon
> Cc: modperl@apache.org
> Subject: Re: Cookie problem under mod_perl :( . Need help.
>
>
>
> Ok. Trying this code:
> ==
> $r = Apache->request();
> my $headers_out = $r->headers_out;
>
> $headers_out->add('Set-Cookie', 'SESSION=1A91933A; domain=abe;');
> $headers_out->add('Set-Cookie', 'fefe=jkwq;');
> $r->send_http_header();
> ...
> ==
> Cookie 'fefe=jkwq' has been sent.
> Cookie 'SESSION=1A91933A; domain=abe;' has been lost,
> disappeared, stuck
> somewhere..
>
> What's the problem now? I got right hash ref, I used ->add() method ..
> but cookie hadn't been added! Why do we need this hash ref. that
> $r->headers_out()
> returns???
>
> / Vlad.
>
> Robin Berjon wrote:
> >
> > At 20:06 24/02/2000 +0300, Vlad Safronov wrote:
> > >sub handler {
> > > my( %form, $ua, $r, $key, $value);
> > > $r = Apache->request();
> > >
> > > my $headers_out = $r->headers_out;
> > > my $headers_in = $r->headers_in;
> > > my %h = $r->headers_in();
> > > $headers_out->{Cookie} = 'SESSION=1A91933A; domain=acme.com';
> >
> > As per Stas's request that we post even when unsure
> (actually I think if I
> > had slept last night it'd be clearer :).
> >
> > I think you shouldn't assign $r->headers_out to a value and
> use it like
> > that. Try either:
> >
> > $r->header_out('Set-Cookie', 'foocookiecontent'); # notice
> it's singular
> > # or
> > my $h_out = $r->headers_out; # plural here
> > $h_out->add('Set-Cookie', 'foocookiecontent');
> > # or do without the assignment
> > $r->headers_out->add('Set-Cookie', 'foocookiecontent');
> >
> > Similarly (though that's not affecting your program) you're
> assigning
> > headers_in to a variable which you're not using afterwards.
> >
> > hth
> >
> > .Robin
> > Earth is a beta site.
>
> --
>
> Best regards,
> ******************************************************
> Vlad A. Safronov vlads@comptek.ru
> CompTek Intl. www.yandex.ru, www.comptek.ru
> Tel.: +7(095)785-2525, ext. 586
>
Re: Cookie problem under mod_perl :( . Need help. [ In reply to ]
Hi Geoffrey!

Yeah! You are right!!! I'm total RFC incompatible!
I'd just done as you recommend and everything worked!

Thanks a lot!

/Vlad.

Geoffrey Young wrote:
>
> according to RFC 2109, a set-cookie domain must always start with a dot...
> it also says that the domain has to match the request host...
>
> thus, try something like
> $headers_out->add('Set-Cookie', 'SESSION=1A91933A; domain=.comptek.ru;');
> instead...
>
> HTH
>
> --Geoff
>
> > -----Original Message-----
> > From: Vlad Safronov [mailto:vlads@comptek.ru]
> > Sent: Friday, February 25, 2000 5:07 AM
> > To: Robin Berjon
> > Cc: modperl@apache.org
> > Subject: Re: Cookie problem under mod_perl :( . Need help.
> >
> >
> >
> > Ok. Trying this code:
> > ==
> > $r = Apache->request();
> > my $headers_out = $r->headers_out;
> >
> > $headers_out->add('Set-Cookie', 'SESSION=1A91933A; domain=abe;');
> > $headers_out->add('Set-Cookie', 'fefe=jkwq;');
> > $r->send_http_header();
> > ...
> > ==
> > Cookie 'fefe=jkwq' has been sent.
> > Cookie 'SESSION=1A91933A; domain=abe;' has been lost,
> > disappeared, stuck
> > somewhere..
> >
> > What's the problem now? I got right hash ref, I used ->add() method ..
> > but cookie hadn't been added! Why do we need this hash ref. that
> > $r->headers_out()
> > returns???
> >
> > / Vlad.
> >
> > Robin Berjon wrote:
> > >
> > > At 20:06 24/02/2000 +0300, Vlad Safronov wrote:
> > > >sub handler {
> > > > my( %form, $ua, $r, $key, $value);
> > > > $r = Apache->request();
> > > >
> > > > my $headers_out = $r->headers_out;
> > > > my $headers_in = $r->headers_in;
> > > > my %h = $r->headers_in();
> > > > $headers_out->{Cookie} = 'SESSION=1A91933A; domain=acme.com';
> > >
> > > As per Stas's request that we post even when unsure
> > (actually I think if I
> > > had slept last night it'd be clearer :).
> > >
> > > I think you shouldn't assign $r->headers_out to a value and
> > use it like
> > > that. Try either:
> > >
> > > $r->header_out('Set-Cookie', 'foocookiecontent'); # notice
> > it's singular
> > > # or
> > > my $h_out = $r->headers_out; # plural here
> > > $h_out->add('Set-Cookie', 'foocookiecontent');
> > > # or do without the assignment
> > > $r->headers_out->add('Set-Cookie', 'foocookiecontent');
> > >
> > > Similarly (though that's not affecting your program) you're
> > assigning
> > > headers_in to a variable which you're not using afterwards.
> > >
> > > hth
> > >
> > > .Robin
> > > Earth is a beta site.
> >
> > --
> >
> > Best regards,
> > ******************************************************
> > Vlad A. Safronov vlads@comptek.ru
> > CompTek Intl. www.yandex.ru, www.comptek.ru
> > Tel.: +7(095)785-2525, ext. 586
> >

--

Best regards,
******************************************************
Vlad A. Safronov vlads@comptek.ru
CompTek Intl. www.yandex.ru, www.comptek.ru
Tel.: +7(095)785-2525, ext. 586