Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

my $cookie = cookie( -NAME=> $cookie, -VALUE=> $pw, -EXPIRES => "+24h", ); print header(-COOKIE => $cookie, -expires=>'now');
When setting a cookie, I can't seem to get other EXPIRE formats to work. If I try +1m, it doesn't seem to accept my cookie if I reload the screen the second after I sign in. Same thing goes with +24h or +10h or +1d or +10d, the cookie doesn't stick.

The only one that I can find that works is +1year, this DOES work while nothing else does. Can anyone explain to me why this might be? I really don't want to have to login just once a year, I'd rather it be once per few hours OR they have to login whenever they close the browser window.

Replies are listed 'Best First'.
Re: cookie setting
by b10m (Vicar) on Feb 02, 2004 at 16:47 UTC
    my $cookie = cookie( -NAME=> $cookie, -VALUE=> $pw, -EXPIRES => "+24h", );

    The thing that strikes me as odd is -NAME=> $cookie. Is this the real code, or is it just a typo in this example? I think something like -NAME=>'pw' is going to work better.

    For me, this is working rather well:

    my $cookie = cookie(-name=>'username', -value=>$username, -expires=>'+5d', -path=>'/', -domain=>$domain, );
    --
    b10m

    All code is usually tested, but rarely trusted.
Re: cookie setting
by bkiahg (Pilgrim) on Feb 02, 2004 at 16:50 UTC
    If you want to delete the cookie when they close the browser don't set an expire time. And the browser won't keep the cookie. Food for thought.
Re: cookie setting
by borisz (Canon) on Feb 02, 2004 at 16:36 UTC
    Check the clocks on the client and server ;-)
    Boris