#!c:/perl/bin/perl.exe
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
use warnings 'all';
my $query = CGI->new();
my $cookie = &make_cookie;
print $query->header(-cookie => $cookie), $query->start_html, "
Cookie Page
", $query->end_html;
##################################################
sub make_cookie {
my $cookie_id = &make_random_64_id;
my $cookie = cookie(-name => 'login', -value => $cookie_id, -path => '/'); # Expires when browser is closed
return $cookie;
}
##################################################
# Make random cookie ID from 64 random alphanumeric characters.
sub make_random_64_id {
my $rand_id;
my @alpha_nums = ('a'..'z', 'A'..'Z', '0'..'9');
for (1..64) {
$rand_id .= $alpha_nums[int(rand(@alpha_nums))];
}
return $rand_id;
}