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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why won't this work?

Status
Not open for further replies.

MagicChris

Programmer
Joined
May 30, 2001
Messages
28
Location
GB
Hello,

I recently adapted a script so it functions like a self contained website. Fairly easy stuff and i'm just doing it for a test but might actually use it.
Every time i load it it brings up a 500 internal error...I've chmodded it to 700...and then tried 755 also but it won't work.
I can't even see what is wrong in the script writing, i've checked, re-checked, but to no avail.

It has been saved as zigwebdesign.pl

Please help. The source can be viewed @
Thanks,
Chris G.
 
The 500 error means your code failed to produce a compliant HTTP header. Typically, this happens when your code fails to compile and run - therefore no header is produced. Some possible reasons....
1 - the first line of your cgi code does not point at the perl interpreter on the server
2 - you are trying to open a handle to a file that the web server does not have
sufficient permissions to... or anything else that would cause a 'die' in the code.
3 - you are writing your code on a Win box and uploading to a UNIX box and are
forgetting to convert your line endings to UNIX flavor.
4 - you are trying to run on a UNIX box and have not set the execute bits.
5 - you have a syntax error in your code and it simply will not run.


You might try posting some of what you are trying to do and let us take a look.

HTH


keep the rudder amid ship and beware the odd typo
 
Well i did put a link to all of the work in the script,
here it is anyway:

#!/usr/bin/perl
use vars qw(%config %form);
use strict;
#-###########################################################################
# This website designed by ZigWebDesign.co.uk
#
#-###########################################################################

#-#############################################
# Configuration Section
# Edit these variables!
local %config;

# The Base Directory. We need an
# absolute path for the base directory.
# Include the trailing slash. THIS SHOULD
# NOT BE WEB-ACCESSIBLE!

$config{'basepath'} = '../
# Image Dir
# This is where images are stored.

$config{'imagedir'} = '../images';

# Files Directory
# This is where other files are stored.

$config{'filedir'} = 'files';

# You can configure your own header which will
# be appended to the top of each page.

$config{'header'} =<<&quot;EOF&quot;;
<html>
<head>
<meta http-equiv=Content-Type
content=text/html; charset=iso-8859-1>
<meta name=GENERATOR content=Microsoft FrontPage Express 2.0>
<title>Zig Web Design</title>
<style type=text/css>
<!--
a{text-decoration:none}
.menu:hover{color:#9767C7; }

.menu { font-size: 14px;
color: #000000;
font-weight: bold;
font-family: arial;
-->
</style>
</head>
<body bgcolor=#FFFFFF link=#000000 vlink=#000000>
<div align=center><center>

<table border=0 cellpadding=0 cellspacing=0 width=670>
<tr>
<td><p align=right><MAP NAME=FrontPageMap0><AREA SHAPE=RECT COORDS=10, 68, 42, 81 HREF=$ENV{'SCRIPT_NAME'} TARGET=_self><AREA SHAPE=RECT COORDS=49, 68, 88, 81 HREF=$ENV{'SCRIPT_NAME'}?action=contact TARGET=_self><AREA SHAPE=RECT COORDS=94, 68, 127, 81 HREF=$ENV{'SCRIPT_NAME'}?action=about TARGET=_self></MAP><img src=$config{'imagedir'}/1.gif border=0 width=134 height=85 usemap=#FrontPageMap0></p>
</td>
<td><img src=$config{'imagedir'}/2.gif width=534 height=85></td>
</tr>
<tr>
<td valign=top background=$config{'imagedir'}/3a.gif><br>
<p align=center><a href=$ENV{'SCRIPT_NAME'}?action=portfolio class=menu title=Portfolio><b><font face=Arial size=2>Portfolio</font></b></a></p>
<p align=center><a href=$ENV{'SCRIPT_NAME'}?action=banner class=menu title=Banner Design><b><font face=Arial size=2>Banner Design</font></b></a></p>
<p align=center><a href=$ENV{'SCRIPT_NAME'}?action=prices class=menu title=Pricing Info><b><font face=Arial size=2>Pricing</font></b></a></p>
<p align=center><img src=\&quot;$config{'imagedir'}/dots.gif\&quot; border=\&quot;0\&quot;></p>
<p align=center><font face=Arial><strong></strong></font>&nbsp;</p>
<p align=center><font face=Arial><strong></strong></font>&nbsp;</p>
<p align=center><font face=Arial><strong></strong></font>&nbsp;</p>
</td>
<td valign=top>
EOF

# You can configure your own footer which will
# be appended to the bottom of each page.
# Although not required, a link back to
# everysoft.com will help to support future
# development.

$config{'footer'} =<<&quot;EOF&quot;;
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align=center><center><table border=0
cellpadding=0 cellspacing=0 width=80\%>
<tr>
<td width=100\%><p align=center><font size=1
face=Arial>Copyright \© 2001 Zig Web Design</font></p>
</td>
</tr>
</table>
</center></div></td>
</tr>
</table>
</center></div>
</body>
</html>
EOF

#-#############################################
# Main Program
# You do not need to edit anything below this
# line.

#-#############################################
# Print The Page Header
#
print $config{'header'};
#
#-#############################################

local %form = &get_form_data;
if ($form{'action'} eq 'about') { &about; }
elsif ($form{'action'} eq 'banner') { &banner; }
elsif ($form{'action'} eq 'contact') { &contact; }
elsif ($form{'action'} eq 'portfolio') { &portfolio; }
elsif ($form{'action'} eq 'prices') { &prices; }
else { &index; }

#-#############################################
# Print The Page Footer
#
print $config{'footer'};
#
#-#############################################

#-#############################################
# Sub: index
#

sub index {
print <<&quot;EOF&quot;;
<div align=center><center><table
border=0 cellpadding=5 cellspacing=0 width=80\%>
<tr>
<td rowspan=2 colspan=2 width=100\%><p
align=center><font color=#400080 size=3
face=Arial><strong><u>Home</u></strong></font></p>
<p><font size=2 face=Arial><strong>As a web
design and construction company it is our aim to
provide you, the customer, with the best website
that we are capable of making, at sensible
prices.</strong></font></p>
<p><font size=2 face=Arial>I am an individual
targeting my services at small businesses and
websites.<br>
Prices will be low as I am using this opportunity
for experience.</font></p>
<p><font size=2 face=Arial>Your website is
open to millions of users around the world, 24
hours a day, 7 days a week and in competition
with the increasing numbers of websites popping
up everyday on the Web. <br>
Therefore it is necessary for it to be both user
friendly and aesthetically pleasing.</font></p>
<p><font size=2 face=Arial>The sheer speed
and convenience of the Internet makes information
grabbing and shopping increasingly popular
through the age range.</font></p>
</td>
</tr>
</table>
</center></div>
EOF
}

#-#############################################
# Sub: about
#

sub about {
print <<EOF&quot;;
<div align=center><center><table
border=0 cellpadding=4 cellspacing=0 width=80\%>
<tr>
<td width=100\%><p align=center><font
color=#400080 size=3 face=Arial><strong><u>About
us</u></strong></font></p>
<p><font size=2 face=Arial>This is a one
manned company, based in the UK, targeting my
services at small businesses and websites.</font></p>
<p><font size=2 face=Arial>I can provide
proffesionally designed and crafted website
templates but will also provide website
maintenance for a cheap hourly based fee. <br>
I am able to write in html, provide graphic
design and can install and edit javascript, dhtml
and cgi programs.</font></p>
<p><font size=2 face=Arial>As a customer you
will recieve help and answers about the website
that you have purchased as long as we stay open.</font></p>
<p><font size=2 face=Arial>Our services are
priced sensibly and very affordable.</font></p>
</td>
</tr>
</table>
</center></div>
EOF
}

#-#############################################
# Sub: Banner Design
#

sub banner {
print <<&quot;EOF&quot;;
<div align=center><center><table
border=0 cellpadding=4 cellspacing=0 width=80\%>
<tr>
<td width=100\%><p align=center><font
color=#400080 size=3 face=Arial><strong><u>About
us</u></strong></font></p>
<p><font size=2 face=Arial>This is a one
manned company, based in the UK, targeting my
services at small businesses and websites.</font></p>
<p><font size=2 face=Arial>I can provide
proffesionally designed and crafted website
templates but will also provide website
maintenance for a cheap hourly based fee. <br>
I am able to write in html, provide graphic
design and can install and edit javascript, dhtml
and cgi programs.</font></p>
<p><font size=2 face=Arial>As a customer you
will recieve help and answers about the website
that you have purchased as long as we stay open.</font></p>
<p><font size=2 face=Arial>Our services are
priced sensibly and very affordable.</font></p>
</td>
</tr>
</table>
</center></div>
EOF
}

#-#############################################
# Sub: Contact
#

sub contact {
print <<&quot;EOF&quot;;
<div align=center><center><table
border=0 cellpadding=4 cellspacing=0 width=80\%>
<tr>
<td width=100\%><p align=center><font
color=#400080 size=3 face=Arial><strong><u>Contact</u></strong></font></p>
<p align=center><font size=2 face=Arial><strong>general
enquiries : : </strong></font><a
href=info@zigwebdesign.co.uk class=menu><font
size=2 face=Arial><strong>info@zigwebdesign.co.uk</strong></font></a></p>
<p align=center><font size=2 face=Arial><strong>sales
enquiries : : </strong></font><a
href=mailto:sales@zigwebdesign.co.uk
class=menu><font size=2 face=Arial><strong>sales@zigwebdesign.co.uk</strong></font></a></p>
<p align=center><font size=2 face=Arial>I will get back to you as soon as possible.</font></p>
</td>
</tr>
</table>
</center></div>
EOF
}

#-#############################################
# Sub: Portfolio
#

sub portfolio {
print <<&quot;EOF&quot;;
<div align=center><center><table
border=0 cellpadding=4 cellspacing=0 width=80\%>
<tr>
<td width=100\%><p align=center><font
color=#400080 size=3 face=Arial><strong><u>Contact</u></strong></font></p>
<p align=center><font size=2 face=Arial><strong>general
enquiries : : </strong></font><a
href=info@zigwebdesign.co.uk class=menu><font
size=2 face=Arial><strong>info@zigwebdesign.co.uk</strong></font></a></p>
<p align=center><font size=2 face=Arial><strong>sales
enquiries : : </strong></font><a
href=mailto:sales@zigwebdesign.co.uk
class=menu><font size=2 face=Arial><strong>sales@zigwebdesign.co.uk</strong></font></a></p>
<p align=center><font size=2 face=Arial>I will get back to you as soon as possible.</font></p>
</td>
</tr>
</table>
</center></div>
EOF
}

#-#############################################
# Sub: Prices
#

sub prices {
print <<&quot;EOF&quot;;
<div align=center><center><table
border=0 cellpadding=4 cellspacing=0 width=80\%>
<tr>
<td width=100\%><p align=center><font
color=#400080 size=3 face=Arial><strong><u>Pricing
Information</u></strong></font></p>
<p align=left><font size=2 face=Arial>My
services are currently very cheap as I am using
this opportunity to build up my experience.</font></p>
<p align=left><font size=2 face=Arial>Prices
are as listed in the following tables.</font></p>
<table border=0 cellspacing=3 width=100\%>
<tr>
<td bgcolor=#808080><font size=2
face=Arial><strong>Item</strong></font></td>
<td bgcolor=#808080><font size=2
face=Arial><strong>Price</strong></font></td>
</tr>
<tr>
<td valign=top><font size=2
face=Arial>One website</font></td>
<td valign=top><p align=left><font
size=2 face=Arial>\£100 deposit. This
is refundable if you are not satisfied
with the finished designs.<br>
<br>
\£20 per hour<br>
This is graduated in 15 minute
increments.</font></p>
</td>
</tr>
<tr>
<td valign=top><font size=2
face=Arial>Domain registration and
webspace</font></td>
<td valign=top><font size=2
face=Arial>This can be purchased from </font><a
href= class=link
target=_blank><font size=2
face=Arial> size=2 face=Arial> or any other
place.<br>
Your designed site can then be uploaded
to this webspace.</font></td>
</tr>
<tr>
<td valign=top><font size=2
face=Arial>Uploading to existing web
server</font></td>
<td valign=top><font size=2
face=Arial>no extra charge.</font></td>
</tr>
<tr>
<td valign=top><font size=2
face=Arial>Maintenance<br>
(done on request)</font></td>
<td valign=top><font size=2
face=Arial>\£20 per hour<br>
This is graduated in 15 minute
increments.<br>
If a change only takes a moment then this
is free of charge.</font></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><font size=2 face=Arial>Banner
design</font></td>
<td><font size=2 face=Arial>\£5 per
banner</font></td>
</tr>
</table>
</td>
</tr>
</table>
</center></div>
EOF
}

#-#############################################
# Sub: Get Form Data
# This gets data from a post.

sub get_form_data {
my $temp;
my $buffer;
my @data;
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
foreach $temp (split(/&|=/,$buffer)) {
$temp =~ tr/+/ /;
$temp =~ s/%([0-9a-fA-F]{2})/pack(&quot;c&quot;,hex($1))/ge;
$temp =~ s/[\r\n]/ /g;
push @data, $temp;
}
foreach $temp (split(/&|=/,$ENV{'QUERY_STRING'})) {
$temp =~ tr/+/ /;
$temp =~ s/%([0-9a-fA-F]{2})/pack(&quot;c&quot;,hex($1))/ge;
$temp =~ s/[\r\n]/ /g;
push @data, $temp;
}
return @data;
}

#-#############################################
# Sub: Oops!
# This generates an error message and dies.

sub oops {
print &quot;<P><HR SIZE=1 NOSHADE><FONT COLOR=#FF0000><B>Error:</B></FONT><BR>$_[0]<P>Please hit the back browser on your browser to try again or contact <A HREF=\&quot;mailto:$config{'admin_address'}\&quot;>the auction administrator</A> if you belive this to be a server problem.<HR SIZE=1 NOSHADE>\n&quot;;
print $config{'footer'};
die &quot;Error: $_[0]\n&quot;;
}
 
I don't see that you are printing a content type header anywhere. You need to do this first so the browser will know it's getting html. Somewhere you need to do this:
Code:
print &quot;Content-type: text/html\n\n&quot;;
Note that the two newlines are required (i.e. there must be a blank line after the content type header).
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Put that in now, here:

#-#############################################
# Print The Page Header
#
print &quot;Content-type: text/html\n\n&quot;;
print $config{'header'};
#
#-#############################################

But it is still not working,
even with a blank line after it does not work.

#-#############################################
# Print The Page Header
#
print &quot;Content-type: text/html\n\n&quot;;

print $config{'header'};
#
#-#############################################

Chris G.
 
I loaded your program into my trial version of ActiveState Komodo and it flagged the following syntax errors.

The first line of the banner subroutine shouldn't have quotes around EOF.

The first line of the contact subroutine shouldn't have quotes around EOF.

The first line of the portfolio subroutine shouldn't have quotes around EOF.

The first line of the prices subroutine shouldn't have quotes around EOF.

It's also showing a &quot;string found where operator expected&quot; in your get_form_data subroutine on the line with the pack, but I can't see anything wrong with that. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Thanks, but it's still persisting on not working.
It seems like there's nothing wrong, but it just won't work.
 
Komodo apparently isn't as good as it could be about reporting errors, but here's something else I found. You need to escape all the @ in email addresses in your html. That will give you a syntax error too.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Take the quotes out from around EOF in ALL locations. The subroutine about has only ONE quote, which would cause a problem.

I removed all quotes from around EOF and escaped all @ in @zigwebdesign and it ran ok.

Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
You won't beleive this, all that was causing it was one missed &quot; on the Sub for about.

sub about {
print <<EOF&quot;;

Grrr! silly me :)

Thanks to everyone for helping anyway,
Chris G.
 
Must have found the error at the same time. It's ok with quotes around EOF, just because i missed off one quote mark.

Thanks,
Chris G.
 
Unmatched quotes are a common error, and one of the hardest to find. Komodo noticed something was wrong, but didn't catch what the REAL problem was. Why can't it at least SUGGEST that there might be a missing quote if it reaches the end of a line without finding a closing quote? I try to never have my literals extend across multiple lines for just that reason.

You should probably still escape those @.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top