【问题标题】:What's this "End of script output before headers"?这是什么“标题之前的脚本输出结束”?
【发布时间】:2017-02-25 03:42:08
【问题描述】:

我正在尝试用 PERL 做一个简单的测试。我编写了 input.html 并将其放在 hdocs 文件夹中,并将 output.cgi 放在 cgi-bin 中。两者都在 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>

这是当用户按下“转换”时应该显示的 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;

这是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

这就是 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

【问题讨论】:

    标签: apache perl permissions xampp cgi


    【解决方案1】:

    如错误日志所述,Apache 无权执行您的 CGI 文件

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

    顺便说一下,温度的换算应该是

    $celcius = ( $fahrenheit - 32 ) / 1.8
    

    更新

    你的问题就像在问,“我把钥匙放在车里,但我仍然不在莱斯特。我做错了什么?”

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

    如果你真的做不到,那么你就在方式在你的头上,所以你必须停下来学习一些教程

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

    /Applications/XAMPP/xamppfiles/cgi-bin/output.cgi
    

    所以你可以

    chmod a+x /Applications/XAMPP/xamppfiles/cgi-bin/output.cgi
    

    cd /Applications/XAMPP/xamppfiles/cgi-bin
    

    紧随其后

    chmod a+x output.cgi
    

    【讨论】:

    • 你必须添加路径的其余部分。您的 /cgi-bin 目录不会是根目录。或者,您可以 cd 到您的 CGI 文件所在的位置,只需 chmod a+x output.cgi
    • @JohnyB12:查看您的错误日志,output.cgi 位于/Applications/XAMPP/xamppfiles/cgi-bin/output.cgi,因此您可以在chmod a+x /Applications/XAMPP/xamppfiles/cgi-bin/output.cgicd /Applications/XAMPP/xamppfiles/cgi-bin 后跟chmod a+x output.cgi
    • @JohnyB12:“解决问题”而不知道您解决了什么问题以及如何解决它比无法继续更糟糕。如果你很幸运,那么很快就会有另一个你不明白的问题,你必须妥善解决问题。否则几个月后会出现一些你无法解释的事情,这是这个“修复”的结果。如果您希望成为一名有用的程序员,那么准确和彻底是至关重要的。 Sublime Text 和 Text Wrangler 不应该区分工作代码和非工作代码。你走错了路。
    • @JohnyB12:到目前为止,您似乎在提出明智的问题,因此尽管您之前两次投了反对票,但我还是尽力帮助了您。有了这个“解决方案”,很明显你正在寻找一个快速解决方案而不是一个正确的答案,所以你又对我投了反对票。请不要永远通过更改代码来编写软件,直到它看起来可以工作为止。你已经失去了我的尊重。
    • 我想重申@Borodin 所说的话。通过更改随机事物直到它们正常工作来修复程序是一个糟糕的主意。要成为一名成功的程序员,您需要更有条不紊,并且需要了解为什么您的修复工作有效。
    猜你喜欢
    • 2014-05-03
    • 1970-01-01
    • 2019-04-23
    • 1970-01-01
    • 1970-01-01
    • 2018-05-30
    • 2016-03-24
    • 2020-10-26
    • 2014-08-05
    相关资源
    最近更新 更多