Click to See Complete Forum and Search --> : Calculating cookie expiration time based on User's time


web
07-06-2004, 05:57 PM
I'm writing a perl session management system that uses cookies.

I'm using the CGI.PM module to create and manage the cookies.

I want cookies to be deleted an hour after they're created. The problem I'm having is that the cookie expiration time is being based on the server's time, and I want it to be based on the time on the user's computer.

The way I place a cookie now is:

------------
$the_cookie = cookie(-name=>'login',
-value=>\%login,
-path=>'/',
-expires=>'+1h');
print header(-cookie=>the_cookie);
------------

Any ideas on how I could make it 1hour from the time on the user's computer instead of 1hour from the time on the server?

Thanks

Charles
07-07-2004, 10:06 AM
You're going to have to use JavaScript for this. The server doesn't know what's going on at the user agent. See http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/cookies.html and http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/date.html. But keep in mind that not everybody uses JavaScript just like not everybody permits cookies.

web
07-07-2004, 12:02 PM
Ok, thanks for the help.