You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Chris Winters <ch...@cwinters.com> on 2001/06/18 05:14:23 UTC

Re: CGI::Cookie vs Apache::Cookie -- help?

* will trillich (will@serensoft.com) [010617 23:04]:
> mine is similar:
> 
> 	$r->log_error( qq(...id=$ID, sending cookie) );
> 	my $cookie =
> 		Apache::Cookie->new( $r,
> 			-name   => $cookie_name,
> 			-value  => $ID         ,
> 			-domain => $r->hostname,
> 			-path   => '/'         ,
> 		);
> 	$r->header_out('Set-Cookie', => $cookie);
> 
> which sets a cookie value of "SCALAR(0x863c9f8)" instead of the
> $ID string that shows up in the log, which is
> 
> 	...id=483dd0e2202accce6d4d3e07d976bfdc, sending cookie
> 
> in the original ticket example above, -value is a hashref:
> 
> 	-value => { ID => $ID }
> 
> instead of
> 
> 	-value => $ID
> 
> as the Apache::Cookie manpage suggests (a plain scalar value).
> 
> this worked just fine with CGI::Cookie (without the $r, of
> course) -- can't get it to return the actual scalar value with
> Apache::Cookie...
> 
> ideas? help!

>From 'perldoc Apache::Cookie'

   bake
       Put cookie in the oven to bake.  (Add a Set-Cookie
       header to the outgoing headers table.)

           $cookie->bake;

   as_string
       Format the cookie object as a string:

           #same as $cookie->bake
           $r->err_headers_out->add("Set-Cookie" => $cookie->as_string);


HTH

Chris

-- 
Chris Winters (chris@cwinters.com)
Building enterprise-capable snack solutions since 1988.

Re: CGI::Cookie vs Apache::Cookie -- help?

Posted by will trillich <wi...@serensoft.com>.
On Mon, Jun 18, 2001 at 07:18:56AM +0200, Per Einar wrote:
> 
> ----- Original Message -----
> From: "will trillich" <wi...@serensoft.com>
> To: <mo...@apache.org>
> Sent: Monday, June 18, 2001 7:09 AM
> Subject: Re: CGI::Cookie vs Apache::Cookie -- help?

> > what does $cookie->bake do (add set-cookie header) that
> > $r->header_out('set-cookie'=>$cookie) (add set-cookie header)
> > does not?
> >
> > [ and why ain't that mentioned in the manual? ]
> 
> As someone else stated, bake() actually sends a Set-Cookie header, but with
> $cookie->as_string and not just $cookie (which is an instance of
> Apache::Cookie). When you're just sending $cookie you're sending an object
> reference.
> 
> Per Einar Ellefsen
> per.einar@skynet.be

my grok quotient has grown considerably. thanks!

-- 
I figure: if a man's gonna gamble, may as well do it
without plowing.   -- Bama Dillert, "Some Came Running"

will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

Re: CGI::Cookie vs Apache::Cookie -- help?

Posted by Per Einar <pe...@skynet.be>.
----- Original Message -----
From: "will trillich" <wi...@serensoft.com>
To: <mo...@apache.org>
Sent: Monday, June 18, 2001 7:09 AM
Subject: Re: CGI::Cookie vs Apache::Cookie -- help?


> On Sun, Jun 17, 2001 at 11:14:23PM -0400, Chris Winters wrote:
> > * will trillich (will@serensoft.com) [010617 23:04]:
> > > $r->log_error( qq(...id=$ID, sending cookie) );
>
> --this outputs the string i'm hoping for, into the log file.

That's because you're outputting $ID and not the cookie itself, which you're
creating below.

>
> > > my $cookie =
> > > Apache::Cookie->new( $r,
> > > -name   => $cookie_name,
> > > -value  => $ID         ,
> > > -domain => $r->hostname,
> > > -path   => '/'         ,
> > > );
> > > $r->header_out('Set-Cookie', => $cookie);
>
> > From 'perldoc Apache::Cookie'
> >
> >    bake
> >        Put cookie in the oven to bake.  (Add a Set-Cookie
> >        header to the outgoing headers table.)
> >
> >            $cookie->bake;
>
> what does $cookie->bake do (add set-cookie header) that
> $r->header_out('set-cookie'=>$cookie) (add set-cookie header)
> does not?
>
> [ and why ain't that mentioned in the manual? ]

As someone else stated, bake() actually sends a Set-Cookie header, but with
$cookie->as_string and not just $cookie (which is an instance of
Apache::Cookie). When you're just sending $cookie you're sending an object
reference.

Per Einar Ellefsen
per.einar@skynet.be


Re: CGI::Cookie vs Apache::Cookie -- help?

Posted by will trillich <wi...@serensoft.com>.
On Sun, Jun 17, 2001 at 11:14:23PM -0400, Chris Winters wrote:
> * will trillich (will@serensoft.com) [010617 23:04]:
> > 	$r->log_error( qq(...id=$ID, sending cookie) );

--this outputs the string i'm hoping for, into the log file.

> > 	my $cookie =
> > 		Apache::Cookie->new( $r,
> > 			-name   => $cookie_name,
> > 			-value  => $ID         ,
> > 			-domain => $r->hostname,
> > 			-path   => '/'         ,
> > 		);
> > 	$r->header_out('Set-Cookie', => $cookie);

> From 'perldoc Apache::Cookie'
> 
>    bake
>        Put cookie in the oven to bake.  (Add a Set-Cookie
>        header to the outgoing headers table.)
> 
>            $cookie->bake;

what does $cookie->bake do (add set-cookie header) that
$r->header_out('set-cookie'=>$cookie) (add set-cookie header)
does not?

[ and why ain't that mentioned in the manual? ]

-- 
I figure: if a man's gonna gamble, may as well do it
without plowing.   -- Bama Dillert, "Some Came Running"

will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!