Re: I'm missing something in Apache::Cookie

2000-09-18 Thread darren chamberlain

Michael ([EMAIL PROTECTED]) said something to this effect:
 H.
 
 When I retrieve a cookie
 
 %cookies = Apache::Cookie-fetch;
 
 I get a hash that contains the name of the cookie as the key and a 
 scalar reference as the value. 
 Apache::Cookie=SCALAR(0xblah...)
 Can't seem to unravel it to get at the 
 value. Using
 
 %xx = Apache::Cookie-parse($val);
 gives an apparently empty hash, yet retrieving the headers via 
 Apache::Table yields the correct results
 
 Cookie=foo=bar
 
 cook name val
foo  bar
 
 
 So what am I doing wrong with Apache::Cookie that keeps me from 
 returning the cookie value.

This should do it:

my $ac  = Apache::Cookie-new($r);
my $cookies = $ac-fetch;
my %cookies = ();
for (keys %{$cookies}) {
$cookies{$_} = $cookies-{$_}-value;
}

However, I always find it easier to fetch cookies like this:

my $cookies = { map  { $1 = $2 if (/([^=]+)=(.*)/) }
grep !/^$/, split /;\s*/, $r-header_in('cookie') };
$r-pnotes('cookies', $cookies);

No messing with objects or any of that stuff. Putting it into pnotes makes
the hashref accessible to other phases or subroutines easily (you only have
to pass $r). (That's why I use a hashref and not a hash, so I can just put
it directly into pnotes.)

(darren)

-- 
If you wish to drown, do not torture yourself with shallow water.



Re: I'm missing something in Apache::Cookie (fwd)

2000-09-17 Thread Joe Schaefer

"Thomas S. Brettin" [EMAIL PROTECTED] writes:

 from the looks of the code you guys posted, I would guess that
 Cookie-fetch returns a hash reference, not a hash.  Could this be the
 problem?
 

It can return either a hash or a hash reference, depending on whether or not 
you wantarray.  The problem many people encounter is that the values in the
returned hash(ref) are Apache::Cookie OBJECTS, not simply value of the
cookie.  There's more to a cookie than just it's value. 
I think it goes something like this.

%cookies = Apache::Cookie-fetch;

print ref \%cookies; # prints HASH ??
print ref $cookies{'SESSION'}; # prints Apache::Cookie ??
print $cookies{'SESSION'}-value; # prints the value of SESSION cookie

RTFM to be sure, or run it and see what you get!

-- 
Joe Schaefer
[EMAIL PROTECTED]

SunStar Systems, Inc.



I'm missing something in Apache::Cookie

2000-09-15 Thread Michael

H.

When I retrieve a cookie

%cookies = Apache::Cookie-fetch;

I get a hash that contains the name of the cookie as the key and a 
scalar reference as the value. 
Apache::Cookie=SCALAR(0xblah...)
Can't seem to unravel it to get at the 
value. Using

%xx = Apache::Cookie-parse($val);
gives an apparently empty hash, yet retrieving the headers via 
Apache::Table yields the correct results

Cookie=foo=bar

cook name val
   foo  bar


So what am I doing wrong with Apache::Cookie that keeps me from 
returning the cookie value.

Michael



Re: I'm missing something in Apache::Cookie

2000-09-15 Thread Chris Winters

* Michael ([EMAIL PROTECTED]) [000915 17:29]:
 H.
 
 When I retrieve a cookie
 
 %cookies = Apache::Cookie-fetch;
 
 I get a hash that contains the name of the cookie as the key and a 
 scalar reference as the value. 
 Apache::Cookie=SCALAR(0xblah...)
 Can't seem to unravel it to get at the 
 value. Using
 
 %xx = Apache::Cookie-parse($val);
 gives an apparently empty hash, yet retrieving the headers via 
 Apache::Table yields the correct results
 
 Cookie=foo=bar
 
 cook name val
foo  bar
 
 
 So what am I doing wrong with Apache::Cookie that keeps me from 
 returning the cookie value.
 
 Michael

The following seems to work for me in nabbing all the cookies sent and
putting them into a hashref $cookies

   my $cookies = {};
   my $cookie_info = Apache::Cookie-fetch;
   foreach my $name ( keys %{ $cookie_info } ) {
 $cookies-{ $name } = $cookie_info-{ $name }-value;
   }

HTH

Chris

-- 
Chris Winters
Senior Internet Developerintes.net
[EMAIL PROTECTED]   http://www.intes.net/
Integrated hardware/software solutions to make the Internet work for you.



Re: I'm missing something in Apache::Cookie (fwd)

2000-09-15 Thread Thomas S. Brettin


from the looks of the code you guys posted, I would guess that
Cookie-fetch returns a hash reference, not a hash.  Could this be the
problem?


Thomas S. Brettin
Staff Member
Bioscience Division, MS-M888
Los Alamos National Laboratory
Los Alamos, NM 87545
505-665-3334

On Fri, 15 Sep 2000, Chris Winters wrote:

 * Michael ([EMAIL PROTECTED]) [000915 17:29]:
  H.
  
  When I retrieve a cookie
  
  %cookies = Apache::Cookie-fetch;
  
  I get a hash that contains the name of the cookie as the key and a 
  scalar reference as the value. 
  Apache::Cookie=SCALAR(0xblah...)
  Can't seem to unravel it to get at the 
  value. Using
  
  %xx = Apache::Cookie-parse($val);
  gives an apparently empty hash, yet retrieving the headers via 
  Apache::Table yields the correct results
  
  Cookie=foo=bar
  
  cook name val
 foo  bar
  
  
  So what am I doing wrong with Apache::Cookie that keeps me from 
  returning the cookie value.
  
  Michael
 
 The following seems to work for me in nabbing all the cookies sent and
 putting them into a hashref $cookies
 
my $cookies = {};
my $cookie_info = Apache::Cookie-fetch;
foreach my $name ( keys %{ $cookie_info } ) {
  $cookies-{ $name } = $cookie_info-{ $name }-value;
}
 
 HTH
 
 Chris
 
 -- 
 Chris Winters
 Senior Internet Developerintes.net
 [EMAIL PROTECTED]   http://www.intes.net/
 Integrated hardware/software solutions to make the Internet work for you.