Setting Cookie Expiration Without Using the CGI Module : Cookie « CGI « Perl






Setting Cookie Expiration Without Using the CGI Module

    


#!/usr/bin/perl -T

use strict;

my @monthnames = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
my @weekdays = qw/Sunday Monday Tuesday Wednesday Thursday Friday Saturday/;

my $nextweek = time+604800;

my ($sec,$min,$hour,$mday,$mon,$year,$dayname,$dayofyear) = gmtime($nextweek);
$year += 1900;

print "Content-type: text/html\n";
print "Set-Cookie: testcookie=testcookievalue;";
printf ("expires=%s, %02d-%s-%d %02d:%02d:%02d GMT",$weekdays[$dayname],$mday,$monthnames[$mon],$year,$hour,$min,$sec);
print "\n\n";
print "You've received a cookie<p>\n";

exit;

   
    
    
    
  








Related examples in the same category

1.A Simple Cookie Example
2.A Simple Cookie Example Using the CGI Module
3.Retrieving Cookies
4.Setting Cookie Expiration Using the CGI Module
5.Sending Multiple Cookies Using CGI.pm
6.Retrieving Multiple Cookies
7.Create cookie
8.Cookies and Session Tracking
9.Session tracking in our CGI scripts
10.Read cookie value
11.Program to read cookies from the client's computer
12.Time Period Abbreviations for the CGI Module's Header and Cookie Functions