【发布时间】:2015-11-18 15:23:15
【问题描述】:
为什么会出现此错误? server_port() 按预期工作,afaik REMOTE_PORT 也是一个有效的环境变量。
还有其他获取客户端端口号的方法吗?
这是我的完整代码:
#!/usr/bin/perl -w
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);
use strict;
use Cwd;
#################################
my $time = localtime();
my $dir = cwd();
my $parameter = param('name');
my $q = new CGI;
my $addr = $q->remote_host();
my $request = $q->request_method();
my $port = $q->server_port();
print "Content-type:text/html\r\n\r\n";
print '<html>';
print '<head>';
print '<title>Auth2</title>';
print '</head>';
print '<body>';
print "<h1> The time is $time </h1>";
print "<p> Current directory is $dir</p>";
print "<p> Request parameter: $parameter</p>";
print "<p> Remote address: $addr</p>";
print "<p> Remote port: $port</p>";
print "<p> Request method: $request </p>";
print '</body>';
print '</html>';
1;
【问题讨论】:
-
请阅读CGI::Alternatives 并将您的 Perl Web 编程带入 21 世纪 :-)