ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> modperl
modperl
Apache::Cookies - problems with cookies
by Ross Becker other posts by this author
Jul 28 2002 10:50PM messages near this date
[ANNOUNCE] Uttu 0.03 | Using Constants from seperate file
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved