use DB_File;
use constant PACKFMT => "LI";
sub exit_limit_enforced { print(<<"EOT"), exit }
Content-type: text/html
Traffic control limit reached
$_[0]
Your IP: $ip
Last visit: $time
Number of Visits: $visits
EOT
tie my %limit, 'DB_File', './data/rsn_users.dbm';
my $ip = $ENV{REMOTE_ADDR};
my ($time, $visits) = exists $limit{$ip}
? unpack PACKFMT, $limit{$ip}
: (time() - 21, 0);
$visits = 0 if $time < time() - 86400;
exit_limit_enforced("You reloaded too soon!")
if $time > time() - 20;
exit_limit_enforced(
"You are over the allowed number of visits per day!
"
. "You may not visit again before" . localtime($time + 86400)
) if $visits > 15;
$limit{$ip} = pack PACKFMT, $time, $visits;
untie %limit;