我想获取访问者的ip地址记录。我可以用PHP做到这一点,但是当我尝试这个Perl代码(Perl中的新手)时,当访问者访问我的网站时,它只记录我网站的主机IP地址(在这种情况下为三脚架),如下所示:19Apr11 20:25 :35 10.126.24.9。但那不是我想要的;我想要访客的IP地址?我在这里做错了什么?感谢Perl代码获取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的);我的$ date = strftime('%d%b%y%H:%M:%S',localtime);' – toolic 2011-04-19 21:16:12