> -----Original Message-----
> From: Paul [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, May 23, 2000 7:39 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Cookies
>
>
> > Is there an easier way to accomplish this? I seem to recall
> > that Apache has a simplfied way of setting a cookie upon the
> > initial request if one wasn't yet set, but I can't find anything
> > in the docs.
>
> I'm doing something vaguely similar.
> ========================================
> sub handler {
> my($r,$cookie);
> $r = shift; # the request object
> if ($cookie = $r->header_in('Cookie')
> and $cookie =~ /somevalue/o) {
> # ... got the cookie, do some code....
> } else { # no cookie, so set one
> my $val = 'something useful';
> $r->headers_out->add('Set-Cookie' =>
> "name=$val; path=/;");
> }
> # ... return something useful
> }
> ===================================================================
>
> $r->header_in('Cookie') reads the HTTP headers the browser sent with
> the request, which include Cookies.
since you use headers_out() already, you might want to try using
headers_in() just for style points :)
$r->headers_in->{'Cookie'}
>
> $r->headers_out->add('Set-Cookie' => "CUID=$usr; path=/;") adds a
> Set-Cookie header to the HTTP header lines going out with the
> response.
>
> I do have a question, though. Don't seperate cookies coming in from
> the browser get seperate Cookie: headers? This code is working, but I
> don't want to build it to break later. Should I be reading them into
> an array?
different cookies appear as one value in the headers, separated by a
semi-colon. try something like:
my @cookies = split /; /, $r->headers_in->{'Cookie'};
>
> Also, as I mentioned earlier, I couldn't get "domain=...;" to work.
> Suggestions?
make sure that the domain has a dot in front of it and that it matches the
hostname of the box (RFC 2109):
$headers_out->add('Set-Cookie', "name=$val; domain=.foo.com;");
HTH
--Geoff
>
> Anyway, hope that helps.
> Feel free to offer criticisms and suggestions.
>
> Paul
> ====
> Notice on grape nuts box tab (in its entirety):
> "CONTENTS MAY HAVE OCCURRED DURING SHIPPING AND HANDLING"
>
>
> __________________________________________________
> Do You Yahoo!?
> Send instant messages & get email alerts with Yahoo! Messenger.
> http://im.yahoo.com/
>