A few pointers:
-
My web server is set up to execute files that have a .cgi extension as CGI scripts. Only.
Your web server my be set up the same way. Try changing the name of your CGI script
to remote_address.cgi
-
Your CGI script should always print a Content Header. Even though you don't "have to" in
this case, know that everytime the script is execute an error is being generated in the
error log.
-
Opening a file in append mode will create the file if it doesn't exist. You can trim your
12 lines of code down to 3. Also, be sure that the file has the proper permissions or the
web server will not be able to write to it. I recommend touching the file ip.log in the
directory of choice, su'ing to root, chown the group to the web server, and then chmod the
file to 664. If you don't have root access, you can't chown the file and you will have to
chmod it 646 or 666.
Having said all of that, here is the CGI script rewritten:
use strict;
use warnings;
use CGI qw(header);
my $file = '/full/file/path/to/ip.log';
open LOG, '>>', $file or die "can't open ip log: $!\n";
print LOG "$ENV{REMOTE_ADDR}\n";
print header('image/png');
You do want to call the CGI script via it's URL, not it's file path. Good luck. :)