什么是"标题之前的脚本输出结束"?

-3 apache xampp permissions perl cgi

我想用PERL做一个简单的测试.我编写了input.html并将其放在hgi文件夹中,并将其放在cgi-bin中的output.cgi中.两者都在XAMPP文件夹中,使用mac.这也是使用apache.

HTML文件

<!doctype html>
<html lang="en">
  <body>
<form action="/cgi-bin/output.cgi" method="post">
Enter Fahrenheit: <input type="text" name="fahrenheit" /><br />
Enter Distance in Miles: <input type="text" name="distance" /><br />        
<input type="submit" value="Convert!" />
</form>
Run Code Online (Sandbox Code Playgroud)

这是用户按"转换"时应显示的CGI文件

#!/usr/bin/perl -w

use strict;
use warnings;

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";


#### read form data
my $fahrenheit = param('fahrenheit');
my $distance = param('distance');


#### do the math
my $celcius = ($fahrenheit * 18.8) + 32;
my $kilometers = $distance * 1.60934;

#### display results
print "<h2>Assignment 3</h2>";
print "Conversion: <br />";
printf "Celcius: \$%.2f <br />", $celcius;
printf "Kilometers: \$%.2f <br />", $kilometers;
Run Code Online (Sandbox Code Playgroud)

这是Apache的错误日志

 Marker - Oct 15, 2016, 5:56:38 PM
 [Sat Oct 15 17:56:41.765457 2016] [cgi:error] [pid 3086] [client ::1:50144] AH01215: (13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/cgi-bin/output.cgi' failed: /Applications/XAMPP/xamppfiles/cgi-bin/output.cgi, referer: http://localhost/input.html
 [Sat Oct 15 17:56:41.765785 2016] [cgi:error] [pid 3086] [client ::1:50144] End of script output before headers: output.cgi, referer: http://localhost/input.html
Run Code Online (Sandbox Code Playgroud)

这就是localhost中应该显示output.cgi的页面

Server error!

The server encountered an internal error and was unable to complete your request.

Error message: 
End of script output before headers: output.cgi

If you think this is a server error, please contact the webmaster.

Error 500

localhost
Apache/2.4.23 (Unix) OpenSSL/1.0.2h PHP/5.6.24 mod_perl/2.0.8-dev Perl/v5.16.3
Run Code Online (Sandbox Code Playgroud)

Bor*_*din 5

正如错误日志所述,Apache没有执行CGI文件的权限

为每个人使用添加执行权限chmod a+x cgi-bin/output.cgi,它应该适合您

顺便说一句,温度的转换应该是

$celcius = ( $fahrenheit - 32 ) / 1.8
Run Code Online (Sandbox Code Playgroud)

更新

你的问题就像在问:"我把钥匙放在我的车上,而我还没在莱斯特.我做错了什么?"

您似乎无法output.cgi从命令行指定文件的路径.这不是问题:这是一个缺陷.您必须了解有关正在使用的shell的更多信息

如果你真的不能这样做,那么你在方式在你的头顶,所以你必须停止,并通过一些教程工作

查看错误日志,output.cgi位于

/Applications/XAMPP/xamppfiles/cgi-bin/output.cgi
Run Code Online (Sandbox Code Playgroud)

所以你可以

chmod a+x /Applications/XAMPP/xamppfiles/cgi-bin/output.cgi
Run Code Online (Sandbox Code Playgroud)

要么

cd /Applications/XAMPP/xamppfiles/cgi-bin
Run Code Online (Sandbox Code Playgroud)

其次是

chmod a+x output.cgi
Run Code Online (Sandbox Code Playgroud)

  • 我想重申@Borodin所说的话.通过改变随机事物直到它们工作来修复程序是一个糟糕的主意.要成为一名成功的程序员,您需要更加有条不紊,并且需要了解**为什么**您的修复工作有效. (4认同)
  • @ JohnyB12:到现在为止你似乎在问一些明智的问题,所以尽管你以前有过两次投票,我还是试着帮助你.有了这个"分辨率",很明显你正在寻找一个快速解决方案,而不是一个正确的答案,所以你有另一个来自我的downvote.请永远不要***通过更改代码来编写软件,直到它看起来有效.你失去了我的尊重. (3认同)
  • 那么你必须添加其余的路径.你的`/ cgi-bin`目录不是根目录.或者你可以`cd`到CGI文件的位置,只需`chmod a + x output.cgi` (2认同)
  • @ JohnyB12:"解决问题"而不知道你解决了什么问题,以及你如何解决它比无法继续更糟糕.如果你很幸运,那么你将不会很快理解另一个问题,你必须妥善解决问题.否则会在几个月内出现一些你无法解释的事情,并且是这种"修复"的结果.如果您希望成为一名有用的程序员,那么您必须精确而彻底.Sublime Text和Text Wrangler不应该区分工作代码和非工作代码.你走错了路. (2认同)