简体   繁体   English

从html执行perl cgi脚本

[英]executing perl cgi script from html

I'm, trying to run a perl script from html, but I'm getting error during execution. 我正在尝试从html运行perl脚本,但是在执行过程中出现错误。 Here is my html and 2 lines perl code. 这是我的html和2行perl代码。 The error code is not very descriptive just says "Internal Server Error" and some other lines. 错误代码不是很容易描述,只是说“内部服务器错误”和其他一些内容。 I also want to know how to display the receive user name in the perl script. 我还想知道如何在perl脚本中显示接收用户名。

pwd
/var/www/cgi-bin

ls -l
total 4
-rwxr-xr-x 1 root root 49 Aug 26 16:49 username.pl

Html Code: HTML代码:

<html>
<head>
</head>
<body>
<h1> Hello </h1>
<form action="/cgi-bin/username.pl" method="POST">
     <input type="text" name="username">
     <input type="submit">
</form>
</body>
</html>

Perl code: Perl代码:

#!/usr/bin/perl
print "Received user name is\n";

Your Perl script is not generating appropriate CGI headers. 您的Perl脚本未生成适当的CGI标头。 Please read perldoc CGI , or, for a quick answer: 请阅读perldoc CGI或快速答案:

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

my $q = CGI->new();
my $username = $q->param("username");
print $q->header(-type => "text/plain");
print "Received username is $username\n";

1>.my declares the listed variables to be local to the enclosing block, file. 1> .my声明列出的变量在封闭块文件本地。

2>.if you have a text box name user in your html page 2>。如果您的html页面中有一个文本框名称用户

ie something like this:- 即像这样的东西:

<td><b><font color="green" size="3">USER</font><input type="text" name="user" value="">

then try this 然后试试这个

my $user=$query->param("user");

in your cgi script and get the input in the variable $user. 在您的cgi脚本中,并在变量$ user中获得输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM