home  CODE LIBRARY  : Perl Generating Cookie Expiry Date 
Web and Email Hosting
More Information about our Web and Email Hosting Solution. Linux Web HostingWindows

Generating Cookie Expiration Date:

Every once in a while you may have to generate strings for cookies. This can be a _huge_ pain to get working on different web browsers, unless you get the string just right. This function makes things easier:

sub gen_cookie_exp {
my $ts = shift;
my @wdays = qw/Sun Mon Tue Wed Thu Fri Sat/;
my @months = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
my @m;
if (defined($ts)) {
@m = gmtime($ts);
} else {
@m = gmtime();
}
return sprintf('%s, %02d-%s-%04d %02d:%02d:%02d GMT',
$wdays[$m[6]], $m[3], $months[$m[4]],
$m[5] + 1900, $m[2], $m[1], $m[0]);
}


It takes a UNIX timestamp on the command line. If it doesn't get a time
stamp, then it uses the current time. It may seem strange that it
uses a timestamp as its argument, but it is actually very helpful.
Let's see some examples:

# a cookie to expire in 30 minutes

&gen_cookie_exp(time+(60*30));

# 2 hours

&gen_cookie_exp(time+(60*60*2)); # (time+(60*120))

# a day

&gen_cookie_exp(time+(60*60*24));

Just multiply out the seconds, minutes,
hours, etc.

Email and Web Hosting by Internet Connection 2004-2007 ©
Contact IC Support via AIM!  Our SN is ICSupportDesk