I'm trying to run a cgi script on Abyss web server on Windows 10, following a script from CGI & Perl by Mike MCCGrath.
There is a simple HTML form (colours html) that sends data to a CGI script called colours.cgi
The colours.html is
<!DOCTYPE html>
<html>
<head>
<title>Form template</title>
</head>
<body>
<form method="POST" action="http://localhost/colours.cgi">
1:
<input type="text" name="colour1" size="25">
2:
<input type="text" name="colour2" size="25">
3:
<input type="text" name="colour3" size="25">
<input type="submit" value="Send">
</body>
</html>
The colours.cgi script which requires a file called formparser.lib is as follows:
require "formparser.lib";
&parseform;
print "Content-type: text/html\n\n <html>";
print "You entered these colours:";
print "$formdata{'colour1'}, ";
print "$formdata{'colour2'}, ";
print "$formdata{'colour3'} </html>";
Finally the formparser.lib file is:
sub parseform {
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST'){
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
if ($ENV{'QUERY_STRING'}) {
@getpairs = split(/&/, $ENV{'QUERY_STRING'});
push (@pairs, @getpairs); }
}
else {
print "Content-type:text/html\n\n";
print "Unrecognized Request Method - User GET or POST";
}
foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ tr/%(..)/pack("c", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ tr/%(..)/pack("c", hex($1))/eg;
if ($formdata{$key}) {
$formdata{$key} .= ", $value";
}
else {formdata{$key} = $value;}
}
}
1;
So when colours.html opens, I have a form with 3 input fields, where i want to send the names of 3 colours to colours.cgi. However, when I submit I get Error 500.
I have mananged to get other CGI scripts running with the Abyss web server. I have configured the path to Strawberry Perl, and included associated extensions .pl, .cgi etc.
I'm thinking it is something to do with the 'requires lib' part of the script. Is there anything I need to be aware of when using require with lib files in a CGI script, in terms of server setup etc. The Abyss log says
CGI: [C:\strawberry\perl\bin\perl.exe colours.cgi ] URI: /colours.cgi Broken pipe
many thanks John