homepage Welcome to WebmasterWorld Guest from 54.205.197.66
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Help with my script?
Trying to post a basic script but server won't take it.
Eilonwy




msg:3706900
 2:23 am on Jul 25, 2008 (gmt 0)

Hi! I'm trying to do a sort of online treasure hunt for a game and my server doesn't like my script. It keeps having Internal Server Errors, and since it's been over a year since I did any scripting and my eyes are tired of looking at would someone mind checking it for me? This is just a test page.

#!/usr/bin/perl
require "cgi-lib.pl";
&ReadParse;
$mailprog='/usr/lib/sendmail';
$email='username@example.com';
print << "PrintTag";
<html>
<head>
<title>Zachary's Special Treasure Hunt Clue</title>
</head>
<body background="Treasure.gif">
PrintTag
if($in{'starwars'} eq "darth2")
{print <<"PrintTag";
<table width="75%" align="center" valign="center" cellpadding="2" cellspacing="3" border="4" bgcolor="996600">
<tr>
<td width="100%">
<table width="100%" cellpadding="4" >
<tr>
<td align="Center" width="100%" >
<table width="100%">
<tr>
<td align="center" valign="center" bgcolor="ffffcc">
<p align="center"><h1><b><font color="663300">YOU'RE CORRECT<bR>CHECK THE INBOX FOR YOUR NEXT CLUE!</h1></b></font></p></td></tr></table>
</td></tr></table></td></tr></table>
</td></tr></table>
</body></html>
PrintTag
}
else
{print <<"PrintTag";
<html>
<head>
<title>Zachary's Special Treasure Hunt Clue</title>
</head>
<body background="Treasure.gif">
<form action="/cgi-bin/zach.cgi" method="post">
<table width="75%" align="center" valign="center" cellpadding="2" cellspacing="3" border="4" bgcolor="996600"><tr>
<td width="100%">
<table width="100%" cellpadding="4" >
<tr>
<td align="Center" width="100%" >
<table width="100%">
<tr>
<td align="center" valign="center" bgcolor="ffffcc">
<p align="center"><h1><b><font color="663300">CLUE</h1></b></font></p></td></tr></table>
</td></tr></table></td></tr>
<tr>
<td align="Center">
<table width-"100%" align="center">
<tr>
<td width="50%" align="center" bgcolor="ffffcc">
<p align="center">That is incorrect, please try again.<?p>
</td></tr></table>
</td></tr>
<tr>
<td align="Center">
<table width-"100%" align="center">
<tr>
<td width="50%" align="center" bgcolor="ffffcc">
<p align="center">Which of the following clips are from The Empire strikes Back?<?p>
</td></tr></table>
</td></tr>
<tr>
<td align="Center">
<table width-"100%" align="center">
<tr>
<td width="100%" align="center" bgcolor="ffffcc">
<p align="center"><input type="radio" name="starwars" value="hans">
<A href="han_situation.wav">Option One</a>
<input type="radio" name="starwars" value="darth1"><A href="vader_bidding.wav">Option

Two</a>
<input type="radio" name="starwars" value="yoda"><A href="yoda_900yrs.wav">Option Three</a>
<input type="radio" name="starwars" value="darth2"><A href="vader_easy.wav">Option Four</a>
</p>
</td>
</tr>
</table>
</td></tr>
<tr>
<td align="right">
<table width-"100%" align="right">
<tr>
<td width="100%" align="right">
<p align="center"><input type="submit" value="Submit Answer">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
PrintTag
}

Also, here's what my server tells me: Name "main::email" used only once: possible typo at zach.cgi line 5. Name "main::in" used only once: possible typo at zach.cgi line 13. Name "main::mailprog" used only once: possible typo at zach.cgi line 4. Undefined value assigned to typeglob at cgi-lib.pl line 58. Undefined value assigned to typeglob at cgi-lib.pl line 58. Undefined value assigned to typeglob at cgi-lib.pl line 58. Use of uninitialized value in string eq at zach.cgi line 13.

Thanks!

[edited by: phranque at 5:45 am (utc) on July 25, 2008]
[edit reason] examplified domain [/edit]

 

perl_diver




msg:3707020
 6:18 am on Jul 25, 2008 (gmt 0)

Add the bolded line below:

#!/usr/bin/perl
require "cgi-lib.pl";
&ReadParse;
$mailprog='/usr/lib/sendmail';
$email='username@example.com';
print "Content-type: text/html\n\n";
#the rest of your code follows

That style of coding is more then 10 years old. Hopefully you have cgi-lib.pl on the server. If not you will need to upload that code into the cgi-bin, or into the same folder where the perl script is.

phranque




msg:3707022
 6:29 am on Jul 25, 2008 (gmt 0)

welcome to WebmasterWorld [webmasterworld.com], Eilonwy!

the first major issue you have is that a cgi script returns an HTTP document, not simply an html document.
this means you must first specify a document type header.
first thing in your script add the following:
print "Content-type: text/html\n\n";
the double newlines are important!

now you can return the HTML document.
the "else" clause in your script will output duplicate <html>, <head>, <title> and <body> tags which can also cause some problems once you get that far.

there are some errors in line 58 in the cgi-lib.pl file you are "requiring".
this probably is preventing the "in" hash from being defined which is what gives the line 13 message in your cgi script.
the other messages regarding your script are the defined but unused scalar variables containing string values.

phranque




msg:3707026
 6:36 am on Jul 25, 2008 (gmt 0)

as perl_diver points out - that is an old style of programming.

for one thing, you should look at using the CGI perl module [search.cpan.org].

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved