3

I have a guestbook.htm file in the directory named as Chrome (/home/chankey/Desktop/Chrome/guestbook.htm) whose content is given below

<html>
<head>
<title>Guestbook</title>
</head>
<body>

<form action="/home/chankey/Desktop/Chrome/guestbook.pl" method="get">
<table>
<tr><td>Name</td><td><input name="name" type="text" value=""></td></tr>
<tr><td>E-Mail</td><td><input name="email" type="text" value=""></td></tr>
<tr><td>Location</td><td><input name="loc" type="text" value=""></td></tr>
<tr><td>Comments</td><td>
<TEXTAREA name="comments" rows="10" cols="32"></TEXTAREA></td></tr>
</table><br><br>
<input type="submit" value="Add Entry">
</form>

</body>
</html>

In the same Chrome directory I have one file "guestbook.pl" whose content is

#!/usr/bin/perl

my $query_string = "";
#Get the input
if ($ENV{REQUEST_METHOD} eq 'POST') {
read(STDIN, $query_string, $ENV{CONTENT_LENGTH});
} else {
$query_string = $ENV{QUERY_STRING};
}
##### We will remove this
print "Content-Type: text/html\n\n";
print "Query String is \n<br> $query_string";
##### We will remove this

When I am executing the guestbook.htm file there appears a form, when I fill the data and click on "Add Entry" button a new page opens where the complete script appears.

i.e. the script "guestbook.pl" is not executing. May I know the reason behind this? Why the script is not executing? (I have already given executing permission to this file).

In the httpd.conf file I have added

AddHandler cgi-script cgi pl
<Directory /home/chankey/Desktop/Chrome/>
    Options +ExecCGI
</Directory>

Still it is not executing. Let me know the reason.

4
  • 1
    Are you actually accessing this through your web server (over HTTP), or are you trying to access it from the filesystem (with a file:// URL)? Commented Dec 29, 2011 at 15:22
  • Oops I am using file:///home/chankey/Desktop/Chrome/guestbook.htm Commented Dec 29, 2011 at 15:24
  • Refer this url perlmonks.org/?node_id=44536 Commented Mar 11, 2012 at 12:48
  • I'm using Linux, Devendra. Problem has been solved btw :) Commented Apr 5, 2012 at 18:55

1 Answer 1

4

When you access a file locally (over the file:// type URL in your browser), it's not running from a web server, so:

  • There is no CGI environment
  • The httpd.conf/.htaccess files have no effect

A few ways to deal with this:

  • Create a folder named public_html in your home. Your web server likely has a setting to map http://localhost/~chankey/ to /home/chankey/public_html. (On MacOSX, the preferred name is Sites, instead, I believe.) On an SELinux system, you'll have to specifically grant permission for Apache to use this method.
  • For the specific case of Perl scripts using the standard CGI package, you can also run them manually from a terminal shell, and redirect their output to a temporary file (e.g. >/tmp/output.html), which you can then access
  • Migrate your development workspace into your web server's own directory structure, typically /var/www/html/

PS / unrelated: I strongly recommend that, if you plan to put this on the Internet, you should probably use CGI; use strict; and have the tainting mode enabled #!/usr/bin/perl -WT

Sign up to request clarification or add additional context in comments.

7 Comments

I'd give two more upvotes for the "unrelated" if it were possible!
:-) yeah, I'm a tainting Nazi. It's the #1 thing I miss from Perl in any other language.
Yes, I just had to move htm file to /var/www/html and script file to cgi-bin/ and it worked. Thank you :)
There's no reason to add use CGI to a script that doesn't use anything from CGI.pm — and I wouldn't recommend writing new code to use CGI.pm :)
Why would not recommend using CGI.pm? — given the code above, I would 100% recommend rewriting it to use CGI.pm … it's already subject to multiple security exploits, and it doesn't do anything, yet.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.