12.06.2005

time.cgi


#!/usr/bin/perl -w

=head1 NAME

time.cgi - basic test, for time-limit related stuff

=cut

use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);

my %TIME;
my $minDif;
my $dif;

=over

=item DESCRIPTION

Essentially, this is a test script. It uses the C function to figure out what time it is,
along with how long it's been since the user last visited. It then uses the constant, C
to figure out whether or not C minutes has passed. If it has, it tells the user that they did
whatever it was again. If it hasn't, it tells them how long until they can.

=cut

dbmopen(%TIME, "time", 0644);

use constant numberOfMinutes => 3;

print header();
my ($time) = time();

my $minRem = $TIME{$ENV{REMOTE_ADDR}} + numberOfMinutes * 60;
$minRem-=$time;
$minRem = int($minRem/60);
if ($minRem <= 0 || !defined $TIME{$ENV{REMOTE_ADDR}}) {
$TIME{$ENV{REMOTE_ADDR}} = $time;
print "It's been more than " . numberOfMinutes . " minutes. You did it again.
";
} else {
print "It's been less than " . numberOfMinutes . " minutes. You have $minRem minutes to go.
";
}

=back

No comments: