simX
Unofficial Mac Genius
I've been trying to make a perl CGI script for my website, but I don't have any UNIX server to test it on, so I decided I might as well just test in on my iBook since it has perl installed.
The problem is that when I set it up (I'm following the www.htmlgoodies.com CGI primers tutorial), it doesn't work correctly. In OmniWeb and Mozilla, when the HTML page accesses the cgi script, it just displays the CGI script contents on the page instead of running the script.
I can't figure out what the problem is: I made sure that the path to perl was correct, and that the cgi script was executable, but I still cannot make it work. Is there any way to get this to run locally?
<!-- Here's the HTML page (basically directly from the HTMLgoodies.com tutorial):
<HTML>
<HEAD>
<TITLE>
Guestbook Script
</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<FORM METHOD="post" ACTION="cgi-bin/guestbook.pl">
<INPUT NAME="name" SIZE=50 TYPE="text">
<B>Your Name</B><BR>
<INPUT NAME="email" SIZE=50 TYPE="text">
<B>Your E-Mail Address</B><BR>
<INPUT TYPE="hidden" NAME="submitaddress" VALUE="simX@mac.com">
<B>Write to me below:</B>
<P>
<TEXTAREA NAME="feedback" ROWS=10 COLS=50>
</TEXTAREA>
<P>
<CENTER>
<INPUT TYPE=submit VALUE="SEND">
<INPUT TYPE=reset VALUE="CLEAR">
</CENTER>
</FORM>
</BODY>
</HTML>
And here's the CGI script:
#!/usr/bin/perl
# That is the path to PERL just above It MUST be first in the script
# The following accepts the data from the form
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# The following sends the email
open (MESSAGE,"| /usr/sbin/sendmail -t");
# the default for the above is /usr/lib/sendmail
print MESSAGE "To: $FORM{submitaddress}\n";
print MESSAGE "From: $FORM{name}\n";
print MESSAGE "Reply-To: $FORM{email}\n";
print MESSAGE "Subject: Feedback from $FORM{name} at $ENV{'REMOTE_HOST'}\n\n";
print MESSAGE "The user wrote:\n\n";
print MESSAGE "$FORM{feedback}\n";
close (MESSAGE);
&thank_you;
}
#The following creates the Thank You page display
sub thank_you {
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Thank You!</TITLE>\n";
print "</HEAD>\n";
print "<BODY BGCOLOR=#FFFFCC TEXT=#000000>\n";
print "<H1>Thank You!</H1>\n";
print "\n";
print "<P>\n";
print "<H3>Your feedback is greatly appreciated.<BR>\n";
print "<P>\n";
print "</BODY>\n";
print "</HTML>\n";
exit(0);
} -->
You can download the HTML code and CGI script here:
http://homepage.mac.com/simx/.Public/guestbook.html
http://homepage.mac.com/simx/.Public/guestbook.pl
I would post it, but Apple's HomePage iTools feature doesn't seem to be running on UNIX (or it blocks CGI scripts from running), so it won't work there. Can anybody see if they can get this to work or show me what's wrong? (And, can anybody tell me if you CAN run cgi scripts on HomePage? That would be awesome.)
By the way.. how do I stop the forum from automatically interpreting the HTML. I wanted to post the text, not have MacOSX.com interpret it.