#!/usr/bin/perl

# Set conference name and cookie expiration parameters
# (default is 24 hours from now in format accepted by CGI module)
$conference_name = 'WNEPT2006';
$cookie_expiration = '+24h';

use CGI qw/:standard/;
use Fcntl ':flock';

# See if this client already visited us by retrieving the cookie with the
# conference name
$flag = cookie($conference_name);
if ($flag) {
	# The cookie is already set, just return empty header and
	# do nothing else (keep original expiry)
	print header;
}
else {
	# Increase the value of the counter in the counter file
	open FILE, "+<counter_value";
	flock FILE, LOCK_EX;
	$number = <FILE>;
	seek FILE, 0, SEEK_SET;
	print FILE $number+1;
	close FILE;

	# Generate a cookie in reply with some nonzero value
	$new_cookie = cookie(-name => $conference_name,
		-value => 1,
		-expires => $cookie_expiration);
	print header(-cookie => $new_cookie);
}

# For good manners, also include an empty HTML document
print start_html, end_html;

