나는 방문자의 IP 주소를 기록하려고한다. 나는 PHP로 잘 할 수 있지만 Perl 코드 (초보자 인 Perl)를 사용하면 방문자가 내 사이트로 이동하면 내 웹 사이트의 호스트 IP 주소 (이 경우에는 삼각대) 만 다음과 같이 기록됩니다. 19Apr11 20:25 : 35 10.126.24.9. 그러나 그것은 내가 원하는 것이 아닙니다. 방문자의 IP 주소를 원해? 내가 여기서 뭘 잘못 할 수 있니? 감사합니다IP 주소를 얻는 펄 코드
#!/usr/bin/perl
# For logging IP address of visitors.
# This is stored into the cgi-bin folder and called from the index.htm file
# using <img src="cgi-bin/script.pl">
# Specify location and name of log file to be maintained.
my $LogFileLocation = "iplog.txt";
# Directory must exist and have correct permissions.
use strict;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
$year += 1900;
$year = substr($year,-2);
$mday = $mday < 10 ? "0$mday" : $mday;
$hour = $hour < 10 ? "0$hour" : $hour;
$min = $min < 10 ? "0$min" : $min;
$sec = $sec < 10 ? "0$sec" : $sec;
my $address = $ENV{X_FORWARDED_FOR} || $ENV{REMOTE_ADDR} ||"";
open W,">>$LogFileLocation";
print W "$mday$mon[$mon]$year $hour:$min:$sec\t$address\n";
close W;
# end of script
모든 날짜 코드를 단순화 할 수있다 :'POSIX QW (의 strftime)를 사용; – toolic