#!/usr/bin/perl -w
use Fcntl ":flock";
use strict;
open(IN,"+< counts");
open(OUT,"+< addr");
open(Vijay,">hello143");
eval ( flock IN, LOCK_EX);
$@ and die " It doesnot work with flock: $!";
my $count = <IN>;          # read only the first line.
my $flag = 1;
my $date1 = `date`;
$date1 =~ /\w+\s+(\w+ \d+)\s+(\d+:\d+:\d+) \w+ (\d+)/;
chomp($date1);
my $month1 = $1;
my $time1 = $2;
my $year1 = $3;
my $host = $ENV{'REMOTE_ADDR'};
my $host1 = $ENV{'REMOTE_HOST'};
my @subnet_numbers = split(/\./, $host);
my $packed_address = pack ("C4", @subnet_numbers);
my ($remote_host)  = gethostbyaddr ($packed_address, 2);
$time1 =~ /(\d+):.*/;
my $hr = $1;
while(<OUT>)
{
	$_ =~ /(\d+.\d+.\d+.\d+)\s+\w+\s+(\w+ \d+)\s+(\d+:\d+:\d+) \w+ (\d+)\s+(.*)/;
	my $fi_host = $1;
	my $fi_month = $2;
	my $fi_time1 = $3;
	my $fi_year = $4;
	$fi_time1 =~ /(\d+):.*/;
	my $fi_hr = $1;
	if( $fi_host =~ /$host/ )
	{
	if( $fi_year =~ /$year1/)
	{
	   if( $month1 =~ $fi_month)
	    {
		if( ($hr =~ $fi_hr) || ($hr == ($fi_hr + 1)))
		{
			$flag = 0;
			print Vijay "\n\n zero zero";
			last;
		}
	    }
	}
	}
} 
chomp($count);

if($flag == 1)
{
	$count = $count + 1 ;
	seek(IN ,0,0);
	print IN "$count";
	print OUT "$host\t$date1\t$remote_host\n";
	flock IN, LOCK_UN;
}
else
{
	flock IN, LOCK_UN;
}
print "Content-type: text/html\n\n";
print "<HTML>", "\n";
print "<HEAD>";
print "<meta http-equiv=\"content-type\"  content=\"text/html; charset=ISO-8859-1\">";
print "  <title>index</title>\n</head>";
open(FILE,"<../../Information/delgen.html");
while(<FILE>)
{
print "$_";
}
print "<br><br><p align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"text-align: left; margin-left: auto; margin-right: auto; height: 7%; width: 25%;\">  <tbody>    <tr><td style=\"text-align: center; vertical-align: middle;\"><big><span style=\"color: rgb(204, 102, 0);\">Visitors till now</span></big><br>      </td>      <td style=\"text-align: center; vertical-align: middle; background-color: rgb\(204, 255, 255\);\"><big><span style=\"font-weight: bold;\">$count</span></big><br>      </td>    </tr>  </tbody></table></p>";

