Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to perl

Status
Not open for further replies.

Netwrkengeer

IS-IT--Management
Apr 4, 2001
184
0
0
US
I'm trying to setup a simple perl script on a Unix box, but I keep getting an error. Maybe it is a rights issue maybe it is that I don't know what directories to put the file in. I don't know (there are 3 files The HTML, The CGI, and The .PL) Thanks for your help

This is the error.

"Method Not Allowed
The requested method POST is not allowed for the URL /simple-form.cgi.

Here is the HTML.
[<html>
<head>
<title>A simple form example</title>
</head>
<body>

<H1>This is a simple form using cgi-lib.pl</H1>
<P>
This is a sample form which demonstrates the use of
the <B><A HREF=&quot;cgi-lib.pl&quot;>cgi-lib.pl</A></B> library of
routines for managing form input.
</P>
<HR>
<form method=&quot;post&quot; action=&quot;simple-form.cgi&quot;>
<H2> Pop Quiz: </H2>
What is thy name: <input name=&quot;name&quot;><P>
What is thy quest: <input name=&quot;quest&quot;><P>

Press <input type=&quot;submit&quot; value=&quot;here&quot;> to submit your query.
</form>

</body>
</html> ]

----------------------------------------

here is the script.
[ #!/usr/bin/perl

# $Header: /cys/people/brenner/http/docs/web/RCS/simple-form.cgi,v 1.4 1996/03/29 22:07:56 brenner Exp $
# Copyright (C) 1994 Steven E. Brenner
# This is a small demonstration script to demonstrate the use of
# the cgi-lib.pl library

require &quot;cgi-lib.pl&quot;;

MAIN:
{

# Read in all the variables set by the form
&ReadParse(*input);

# Print the header
print &PrintHeader;
print &HtmlTop (&quot;cgi-lib.pl demo form output&quot;);

# Do some processing, and print some output
($text = $input{'text'}) =~ s/\n/\n<BR>/g;
# add <BR>'s after carriage returns
# to multline input, since HTML does not
# preserve line breaks

print <<ENDOFTEXT;

You, $input{'name'}, whose favorite color is $input{'color'} are on a
quest which is $input{'quest'}, and are looking for the weight of an
$input{'swallow'} swallow. And this is what you have to say for
yourself:<P> $text<P>

ENDOFTEXT


# If you want, just print out a list of all of the variables.
print &quot;<HR>And here is a list of the variables you entered...<P>&quot;;
print &PrintVariables(*input);

# Close the document cleanly.
print &HtmlBot;
} ]

------------------------------

Here is the include.
[ #!/usr/bin/perl

# Perl Routines to Manipulate CGI input
#
# Copyright (c) 1995 Steven E. Brenner
# Permission granted to use and modify this library so long as the
# copyright above is maintained, modifications are documented, and
# credit is given for any use of the library.
#
# Thanks are due to many people for reporting bugs and suggestions
# especially Meng Weng Wong, Maki Watanabe, Bo Frese Rasmussen,
# Andrew Dalke, Mark-Jason Dominus, Dave Dittrich, Jason Mathews

# For more information, see:
# #
# Minimalist http form and script (#
# require &quot;cgi-lib.pl&quot;;
# if (&ReadParse(*input)) {
# print &PrintHeader, &PrintVariables(%input);
# } else {
# print &PrintHeader,'<form><input type=&quot;submit&quot;> Data: <input name=&quot;myfield&quot;>';
#}

# ReadParse
# Reads in GET or POST data, converts it to unescaped text,
# creates key/value pairs in %in, using '\0' to separate multiple
# selections

# Returns TRUE if there was input, FALSE if there was no input
# UNDEF may be used in the future to indicate some failure.

# Now that cgi scripts can be put in the normal file space, it is useful
# to combine both the form and the script in one place. If no parameters
# are given (i.e., ReadParse returns FALSE), then a form could be output.

# If a variable-glob parameter (e.g., *cgi_input) is passed to ReadParse,
# information is stored there, rather than in $in, @in, and %in.

sub ReadParse {
local (*in) = @_ if @_;
local ($i, $key, $val);

# Read in text
if (&MethGet) {
$in = $ENV{'QUERY_STRING'};
} elsif (&MethPost) {
read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
}

@in = split(/[&;]/,$in);

foreach $i (0 .. $#in) {
# Convert plus's to spaces
$in[$i] =~ s/\+/ /g;

# Split into key and value.
($key, $val) = split(/=/,$in[$i],2); # splits on the first =.

# Convert %XX from hex numbers to alphanumeric
$key =~ s/%(..)/pack(&quot;c&quot;,hex($1))/ge;
$val =~ s/%(..)/pack(&quot;c&quot;,hex($1))/ge;

# Associate key and value
$in{$key} .= &quot;\0&quot; if (defined($in{$key})); # \0 is the multiple separator
$in{$key} .= $val;

}

return scalar(@in);
}


# PrintHeader
# Returns the magic line which tells we're an HTML document

sub PrintHeader {
return &quot;Content-type: text/html\n\n&quot;;
}


# HtmlTop
# Returns the <head> of a document and the beginning of the body
# with the title and a body <h1> header as specified by the parameter

sub HtmlTop
{
local ($title) = @_;

return <<END_OF_TEXT;
<html>
<head>
<title>$title</title>
</head>
<body>
<h1>$title</h1>
END_OF_TEXT
}

# Html Bot
# Returns the </body>, </html> codes for the bottom of every HTML page

sub HtmlBot
{
return &quot;</body>\n</html>\n&quot;;
}


# MethGet
# Return true if this cgi call was using the GET request, false otherwise

sub MethGet {
return ($ENV{'REQUEST_METHOD'} eq &quot;GET&quot;);
}


# MethPost
# Return true if this cgi call was using the POST request, false otherwise

sub MethPost {
return ($ENV{'REQUEST_METHOD'} eq &quot;POST&quot;);
}


# MyURL
# Returns a URL to the script

sub MyURL {
local ($port);
$port = &quot;:&quot; . $ENV{'SERVER_PORT'} if $ENV{'SERVER_PORT'} != 80;
return ' . $ENV{'SERVER_NAME'} . $port . $ENV{'SCRIPT_NAME'};
}


# CgiError
# Prints out an error message which which containes appropriate headers,
# markup, etcetera.
# Parameters:
# If no parameters, gives a generic error message
# Otherwise, the first parameter will be the title and the rest will
# be given as different paragraphs of the body

sub CgiError {
local (@msg) = @_;
local ($i,$name);

if (!@msg) {
$name = &MyURL;
@msg = (&quot;Error: script $name encountered fatal error&quot;);
};

print &PrintHeader;
print &quot;<html><head><title>$msg[0]</title></head>\n&quot;;
print &quot;<body><h1>$msg[0]</h1>\n&quot;;
foreach $i (1 .. $#msg) {
print &quot;<p>$msg[$i]</p>\n&quot;;
}
print &quot;</body></html>\n&quot;;
}


# CgiDie
# Identical to CgiError, but also quits with the passed error message.

sub CgiDie {
local (@msg) = @_;
&CgiError (@msg);
die @msg;
}


# PrintVariables
# Nicely formats variables in an associative array passed as a parameter
# And returns the HTML string.
sub PrintVariables {
local (%in) = @_;
local ($old, $out, $output);
$old = $*; $* =1;
$output .= &quot;\n<dl compact>\n&quot;;
foreach $key (sort keys(%in)) {
foreach (split(&quot;\0&quot;, $in{$key})) {
($out = $_) =~ s/\n/<br>\n/g;
$output .= &quot;<dt><b>$key</b>\n <dd><i>$out</i><br>\n&quot;;
}
}
$output .= &quot;</dl>\n&quot;;
$* = $old;

return $output;
}

# PrintVariablesShort
# Now obsolete; just calls PrintVariables

sub PrintVariablesShort {
return &PrintVariables(@_);
}

1; #return true ]
 
Where did you put these scripts? It sounds like the script is not in the /cgi-bin (unless you've placed the HTML in the cgi-bin with the scripts.

Most hosts that I've used disable POST in all directories except for the cgi-bin (by default). But it's easiest if you just place your HTML files in any directory other than /cgi-bin, and then just point your files and forms to the scripts. Notorious P.I.G.
 
I think the admin of the site has Post Disabled and also has anonymous access to the cgi-bin disabled, plus he can not find where the perl directory is. he is using Plesk to install everything,
 
Well I got some tests scripts work, but I still can't get this particular script to work, it gives me an Internal server error.

I'm placing the 2 CGI scripts in the CGI-BIN directory
and the Html file in the Httpdocs.

What could be wrong here, maybe I'm confused, can you give me some general rules to follow to get this going.
 
First, check the chmod settings for the 2 scripts you moved (make sure it's set to 755).

Next, add this bit to beginning of each script (just under the shebang line #!):

Code:
use CGI::Carp qw/fatalsToBrowser carpout/;

BEGIN {
    open(LOG, &quot;>>mycgi-log&quot;) or die(&quot;Unable to open mycgi-log: $!\n&quot;);
    carpout(LOG);
}

This will do 2 things: 1) It will print more useful error information to the browser. 2) If that's not enough, it will also dump 'all' of the error information to a file called 'mycgi-log' in your cgi-bin.

Hopefully that will help you narrow down the problem area(s) in the script. If you can't make out the error descriptions, post them here...

*make sure to remove the above code once you get it running correctly... Notorious P.I.G.
 
On a side note: Did you update the form to point to the scripts' new location?

i.e., <form method=&quot;post&quot; action=&quot;./cgi-bin/simple-form.cgi&quot;> Notorious P.I.G.
 
It still says internal server error, with no added explaination
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top