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. :)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.