in reply to Simple script not being executed when html page loads.
There are a coupld of issues with this script that you could improve:
Here is your script with file locks. It always returns a clear gif to the browser even if the open failed.
#!/usr/bin/perl use Fcntl ':flock'; use MIME::Base64; use CGI qw(header); my $file = "/home/master/webroot/perlskripts/ip.log"; if ( open(my $fh, '>>', $file) ) { # lock the file flock($fh,LOCK_EX); # seek to the end in case someone altered # the file since we opened it seek($fh, 0, 2); # add the entry to the file print $fh "User from ".$ENV{'REMOTE_ADDR'}." logged on\n"; # unlock flock($fh,LOCK_UN); } else { print STDERR "Could not open file for append: $!\n"; } # always send a clear gif to the browser my $q = CGI->new(); $q->header(-type => 'image/gif'); # The following is a base64 encoded 1x1 clear gif image print MIME::Base64::decode_base64('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAA +ALAAAAAABAAEAAAICRAEAOw==');
- Cees
|
|---|