Dear Anonymous Monk,
You have restored my belife, that all programers have a unique sense of humour.
Thank you all for everything in the past.
I actually pulled the counter script apart and inserted the following on the end of Script1.
$filename = 'hits.data';
$main_dir = 'C:/Apache2/cgi-bin/sample';
$autoadd=1;
$view_log='***********';
&FormInput(*input);
$addnew=0;
$lock = "$main_dir/count_lock.lock";
if ($input{'view'} ne $view_log)
{
&SetLock;
}
open(DATA,"$main_dir/$filename");
@lines = <DATA>;
close(DATA);
if ($input{'view'} eq $view_log)
{
}
else
{
open(DATA,">$main_dir/$filename");
foreach $line (@lines)
{
($link_url, $link_count1) = split(/\|/,$line);
if ($input{'url'} eq $link_url1)
{
$link_count1++;
print DATA ("From the Sample script.|$link_count1\n");
$addnew=1;
}
else
{
print DATA $line;
}
}
if ($addnew == 0 && $autoadd == 1)
{
print DATA ("$input{'url'}|1\n");
}
&EndLock;
close(DATA);
if ($input{'url'} !~ m?://?)
{
$input{'url'} = "http://" . $input{'url'};
}
}
exit;
sub FormInput
{
local (*qs) = @_ if @_;
if ($ENV{'REQUEST_METHOD'} eq "GET")
{
$qs = $ENV{'QUERY_STRING'};
}
elsif ($ENV{'REQUEST_METHOD'} eq "POST")
{
read(STDIN,$qs,$ENV{'CONTENT_LENGTH'});
}
@qs = split(/&/,$qs);
foreach $i (0 .. $#qs)
{
$qs[$i] =~ s/\+/ /g;
$qs[$i] =~ s/%(..)/pack("c",hex($1))/ge;
($name,$value) = split(/=/,$qs[$i],2);
if($qs{$name} ne "")
{
$qs{$name} = "$qs{$name}:$value";
}
else
{
$qs{$name} = $value;
}
}
return 1;
}
sub SetLock {
$timecheck = 0;
while(-e $lock)
{
sleep(5);
$timecheck = $timecheck + 1;
if ($timecheck >= 5)
{
unlink("$lock");
}
}
open(LOCKFILE,">$lock");
close(LOCKFILE);
return;
}
sub EndLock {
unlink("$lock");
return;
}
there would be much more left there than I really need . But it workes wonderfully fine . So I am happy. Nasa. |