You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Ross Becker <rb...@extremenetworks.com> on 2002/07/29 00:50:39 UTC

Apache::Cookies - problems with cookies

Hi there folks,
  I'm just getting back into some mod_perl after a fairly lengthy absence,
and I'm running into some troubles with cookies.

Basic summary- I'm trying to set a session ID in a cookie, and it works only
if I do not include an expiration time.

Details:

-------------snip--------------------
 %r_cookies = Apache::Cookies->fetch();
  if ( $r_cookies{'session'} ) {
    Apache::warn('cookie found.');
    $r_sessid = $r_cookies{'session'}->value();
    $r_cookies{'session'}->bake();
  } else {
    my $sessid = create_new_session();
    Apache::warn('cookie created.');
    $cookie = Apache::Cookie->new($r,
                                     -name    =>  'session',
                                     -value   =>  $sessid,
                                     -expires =>  '+7d',
                                     -domain  =>  '.mydomain.com',
                                     -path    =>  '/cgi'
                                     );
    $cookie->bake();
  }
-------------snip--------------------

Ok, that's the example code. Here's what I'm experiencing.
With the code as you see it, every time I hit a page, I get a message in the
log saying that I created a cookie, even though netscape tells me that I'm
modifying an existing cookie on reloads. Netscape sees the cookie, but my
code isn't finding it in the fetched cookies.

If I make one modification to this code- remove the "-expires => '+7d',"
from the cookie creation, remove all cookies from netscape and go look at my
site, everything works perfectly, except that the cookie only lasts until
the browser gets closed. I'd like to have a bit more persistence than that.

Anyone care to explain how I'm being an idiot? I'm sure I'm missing
something here, just not certain what. 

Additionally, anyone got good solutions for looking at the headers being
sent to your browser along with a page, besides using a sniffer? I would
find it useful to check what's being sent to my browser from other web sites
and compare it to what I'm generating to see what I can learn.

Thanks
  --Ross Becker