【问题标题】:Premature end of script headers (perl+index.html)脚本头过早结束 (perl+index.html)
【发布时间】:2012-10-15 20:13:59
【问题描述】:

尊敬的人...

我在 openSUSE 12.2 上,我的 Apache 服务器运行良好......

我复制了 index.html,其中包含:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>Program 7b</title></head>
<body>
<form method="POST" action="http://localhost/cgi-bin/7b.pl">
    Please Enter the Command :
    <input type="text" name="command" id="command" />
    <input type="submit" value="Submit" />
</form>
</body>
</html>

而perl文件如下:

#!/usr/bin/perl

print "Content-type:text/html\n\n";
use CGI

$a = new CGI;
$comm = $a->param("command");
print "The Output of the entered command is:<br />";
system($comm);

cgi-bin目录下的两个文件

但我得到了错误:

脚本标题过早结束 在任何浏览器中运行 localhost/cgi-bin/index.html ....

我已经在apache配置中设置了perl文件的执行...

请帮助解决问题...

问候 -SkyKOG

【问题讨论】:

  • 在系统调用中执行参数时存在非常严重的安全漏洞。如果有人输入rm -rf / 作为命令参数怎么办?此外,您应该始终使用use strict; use warnings;

标签: perl apache cgi


【解决方案1】:

Apache 将 index.html 作为脚本运行,而不仅仅是显示 HTML 文档。 Apache 可能已配置为将 cgi 目录中的任何内容作为脚本运行。

将 html 文件移动到另一个目录。

【讨论】:

  • 是的,这是正确的答案,我是 perl 的新手,刚开始 ..我将这两个文件都保存在 cgi-bin 目录中……当我将 html 文件移动到 htdocs 文件夹时,代码运行良好:) ...
【解决方案2】:

尝试以下工作代码:

#!/usr/bin/perl
use strict; use warnings;
use CGI;

print "Content-type:text/html\n\n";

my $a = new CGI;
my $comm = $a->param("command");

print "The Output of the entered command is:<br />";
system($comm);

建议:永远不要忘记use strict; use warnings; 并使用myour 声明变量。

【讨论】:

  • 这行不通,因为至少use CGI 调用缺少分号。
  • 帖子已相应编辑。从 OP 提供的 index.html 在我的服务器上测试正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-23
  • 1970-01-01
  • 2011-11-01
  • 2012-06-25
  • 2012-04-07
  • 1970-01-01
  • 2021-12-03
相关资源
最近更新 更多