CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
server change causing error messages

 

First page Previous page 1 2 Next page Last page  View All


Lark
Novice

Jan 2, 2004, 9:11 AM

Post #1 of 26 (5167 views)
server change causing error messages Can't Post

i previously was running a microsoft home server for several years, and my scripts ran fine

i added a router at home, lost the home server, move websites to outside apache server, now my scripts won't work...i contacted tech support of the host and we tested a cgi script (test.cgi) and it ran fine, this is the beginning of the script in error
(from this.pl)

Quote


#!/usr/bin/perl

print "Content-type:text/html\n\n";

# Relative path of this.html

$this_file = "http://www.mrlarkins.com/folder/this.html";



the path to perl was checked and is correct, and i have tryed these combinations of the


Quote


/guestbook/guestbook.html gives the following error

[Fri Jan 2 11:36:22 2004] [error] [client 24.144.12.1] Premature end of script headers: /home/virtual/site160/fst/var/www/cgi-bin/guestbook.pl





guestbook/guestbook.html gives the following error

[Fri Jan 2 11:38:01 2004] [error] [client 24.144.12.1] Premature end of script headers: /home/virtual/site160/fst/var/www/cgi-bin/guestbook.pl






../guestbook/guestbook.html gives the following error

[Fri Jan 2 11:44:01 2004] [error] [client 24.144.12.1] Premature end of script headers: /home/virtual/site160/fst/var/www/cgi-bin/guestbook.pl





http://www.mrlarkins.com/guestbook/guestbook.html gives the following error

[Fri Jan 2 11:46:07 2004] [error] [client 24.144.12.1] Premature end of script headers: /home/virtual/site160/fst/var/www/cgi-bin/guestbook.pl



i don't have any more ideas, you got any?


(This post was edited by Lark on Jan 2, 2004, 9:28 AM)


davorg
Thaumaturge / Moderator

Jan 2, 2004, 9:58 AM

Post #2 of 26 (5164 views)
Re: [Lark] server change causing error messages [In reply to] Can't Post

Maybe if you run the program from the command line, you'll see what errors are being displayed before the CGI headers.

Or you could post some of the code here. Debugging code by telepathy gives me a headache :)

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Lark
Novice

Jan 2, 2004, 11:50 AM

Post #3 of 26 (5163 views)
Re: [davorg] server change causing error messages [In reply to] Can't Post

haha, that was funny, i'll try the command line, and will get back to ya


Lark
Novice

Jan 2, 2004, 12:59 PM

Post #4 of 26 (5161 views)
Re: [Lark] server change causing error messages [In reply to] Can't Post

ok, here it is...


Quote




#!/usr/bin/perl

print "Content-type:text/html\n\n";

#===========================

# Initialize the variables

#===========================

# Relative path of Guestbook.html

$guestbook_file = '../guestbook/guestbook.html';

# Initialize list of months

@month = ("January", "February", "March", "April", "May",

"June", "July", "August", "September", "October",

"November", "December");

#===========================

# Read the data from the form

#===========================

if($ENV{'REQUEST_METHOD'} eq "POST"){

$data_length = $ENV{'CONTENT_LENGTH'};

$bytes_read = read(STDIN, $my_data, $data_length);

}

# Let's load it into something we can use

@name_value_array = split(/&/, $my_data);

# Here's where we do the actual work. We're going to cycle

# through @name_value_array to decode the name=value pairs

foreach $name_value_pair (@name_value_array) {

# Split the name=value pair in your HTML form data

($name, $value) = split(/=/, $name_value_pair);

# Now, replace '+' with ' '

$name =~ tr/+/ /;

$value =~ tr/+/ /;

# Next, we'll translate any hex values back into characters

$name =~ s/%(..)/pack("C",hex($1))/eg;

$value =~ s/%(..)/pack("C",hex($1))/eg;



# Finally, we'll load the variables into an associative array

# so we can use it when we need it.

if($form_data{$name})

{

$form_data{$name} .= "\t$value";

}

else

{

$form_data{$name} = $value;

}

}

#===========================

# Get the date and time

# information

#===========================

($Seconds, $Minutes, $Hours, $DayInMonth, $Month,

$ShortYear, $DayOfWeek, $DayOfYear, $IsDST) = localtime(time);

# Make the year four digits instead of just two

$Year = $ShortYear + 1900;

$EntryDate = "$month[$Month] $DayInMonth, $Year";

#===========================

# Open the file, using the

# variable set at the beginning

# of the script.

#===========================

open(GUESTBOOK, "<$guestbook_file") ||

die "Can't open GUESTBOOK: $guestbook_file\n";

# Read the entire file into a list so we can use it later

@guestbook =<GUESTBOOK>;

# ALWAYS close the file when you're done!

close(GUESTBOOK);

#===========================

# Now open it again, but this

# time we'll write to it

#===========================

open(GUESTBOOK, ">$guestbook_file") ||

die "Can't open GUESTBOOK: $guestbook_file\n";

#===========================

# Here's where we write it out

#===========================

foreach $line (@guestbook){

# Check to see if we're at the beginning of the guest book

if($line =~ /<!--My Latest Guest:-->/i) {

#===========================

# We are, so add our latest guest

# Start by adding the guestbook

# header to the file, so we can

# find it next time

#===========================

print GUESTBOOK "<!--My Latest Guest:-->\n";



#===========================

# The guestbook is an HTML

# file, so we'll have to add

# the tags too

#===========================

print GUESTBOOK "<DL>\n";

#===========================

if($form_data{'email'}) {

print GUESTBOOK "<DD><I><B><A HREF=\"mailto:$form_data{'email'}\">

$form_data{'name'}</A></B></I>\n";

} else {

print GUESTBOOK "<DD><B>From : </B><I> $form_data{'name'}</I>\n";

}

print GUESTBOOK "<DD><B>Period: </B><I>$form_data{'period'}</I>\n";



#===========================



#===========================

print GUESTBOOK "<DD><B>Homepage:</B><I><A HREF=\"$form_data{'web'}\">$form_data{'web'}</A></I>\n";



#===========================



#===========================

# add the comments

print GUESTBOOK "<P>\n";

print GUESTBOOK "$form_data{'comments'}\n";

print GUESTBOOK "</P>\n";

#===========================



#===========================

# add the date

print GUESTBOOK "<p><I><font size=2>\n";

print GUESTBOOK "signed on $EntryDate\n";

print GUESTBOOK "</font></I>\n";

#===========================



#===========================

# finish up

print GUESTBOOK "</DL>\n";

print GUESTBOOK "<HR color=blue size=3>\n";

#===========================

}# end: if($line =~ /<!--My Latest Guest:-->/i)

else {

#===========================

# just print the existing

# lines back to the updated file

#===========================

print GUESTBOOK "$line";

}# end: else[if($line =~ /<!--My Latest Guest:-->/i)]

}# end: foreach $line (@guestbook) {

close(GUESTBOOK);





#open (MAIL, "|sendmail -t");

#print MAIL "To: $form_data{'name'}<$form_data{'email'}>\n";

#print MAIL "From: Mr. Larkins <larkinst\@conway.afsc.k12.ar.us>\n";

#print MAIL "Thank you $form_data{'name'} for signing my guestbook. You should be able to view it immediately.\n";

#print MAIL "You submitted the following information to www.MrLarkins.com.\n";

#print MAIL " \n";

#print MAIL "Name: $form_data{'name'}\n";

#print MAIL "Email Address: $form_data{'email'}\n";

#print MAIL "Web Address: $form_data{'web'}\n";

#print MAIL "Class Period: $form_data{'period'}\n";

#print MAIL "Comments:\n";

#print MAIL "$form_data{'comments'}\n";

#print MAIL " \n";

#print MAIL "Thanks.\n";

#print MAIL "Mr. Larkins\n";

#close (MAIL);

#open (MAIL, "|sendmail -t");

#print MAIL "To: Mr. Larkins <tlarkins\@conwaycorp.net>\n";

#print MAIL "From: $form_data{'name'}<$form_data{'email'}>\n";

#print MAIL "Subject: I signed your guestbook\n\n";

#print MAIL "$form_data{'name'} submitted the following entry to your guestbook.\n";

#print MAIL " \n";

#print MAIL "Name: $form_data{'name'}\n";

#print MAIL "Email Address: $form_data{'email'}\n";

#print MAIL "Web Address: $form_data{'web'}\n";

#print MAIL "Class Period: $form_data{'period'}\n";

#print MAIL "Comments:\n";

#print MAIL "$form_data{'comments'}\n";

#close (MAIL);

#===========================

# Let them know their entry

# is added

#===========================

print <<"EOF"

<HTML><TITLE>Entry Submitted</TITLE><HEAD> <META HTTP-EQUIV="refresh" content="4;URL=/home/virtual/site160/fst/var/www/guestbook/guestbook.html"></HEAD><BODY>



<H1>Your GuestBook Entry has been Submitted\!</H1>

Your guestbook entry has been successfully added to the

guestbook and in <font size=24>3</font> seconds you will be taken back to view it.

</BODY>

EOF

#===========================



davorg
Thaumaturge / Moderator

Jan 2, 2004, 1:54 PM

Post #5 of 26 (5159 views)
Re: [Lark] server change causing error messages [In reply to] Can't Post

That is an extremely badly written script and I'd never let it anywhere near a web server that I was running. Before installing CGI programs on a web server I recommend that you read this article.

However there are no syntax errors in it and it seems to run without errors here, so I'm a bit stumped.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Lark
Novice

Jan 2, 2004, 2:05 PM

Post #6 of 26 (5158 views)
Re: [davorg] server change causing error messages [In reply to] Can't Post

i figured there weren't any syntax errors because it worked fine on another server, so my guess is there must be some mis-linked file or something, I don't know anything about apache servers though... i do know they are case sensitive, but thats it!

thats why i first posted only the first part of the script,


Quote
#!/usr/bin/perl

print "Content-type:text/html\n\n";

# Relative path of Guestbook.html

$guestbook_file = '../guestbook/guestbook.html';



what do you suggest the for the link variable link? I've tried everything, but I don't know which it should be


(This post was edited by Lark on Jan 2, 2004, 6:02 PM)


davorg
Thaumaturge / Moderator

Jan 3, 2004, 10:02 AM

Post #7 of 26 (5151 views)
Re: [Lark] server change causing error messages [In reply to] Can't Post

$guestbook_file is the path to guestbook.html on your server. It is used in a call to "open", so it needs to be a file path, _not_ a URL.

To get more information about the error, you could try adding the following to the program.


Code
$|++; 
use CGI::Carp qw(fatalsToBrowser);


Also, what happened when you ran it from the command line?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


(This post was edited by davorg on Jan 3, 2004, 10:04 AM)


Recall
Novice

Jan 3, 2004, 11:24 AM

Post #8 of 26 (5148 views)
Re: [davorg] server change causing error messages [In reply to] Can't Post

Maybe I missed something but I don't see where he used a URL?


davorg
Thaumaturge / Moderator

Jan 3, 2004, 11:28 AM

Post #9 of 26 (5147 views)
Re: [Recall] server change causing error messages [In reply to] Can't Post


In Reply To
Maybe I missed something but I don't see where he used a URL?


Reading slightly between the lines, I see two references to URLs in the first post in this thread.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Recall
Novice

Jan 3, 2004, 11:47 AM

Post #10 of 26 (5146 views)
Re: [davorg] server change causing error messages [In reply to] Can't Post

Aha, it must have been altered where I was looking...



$guestbook_file = '../guestbook/guestbook.html';


(This post was edited by Recall on Jan 3, 2004, 11:48 AM)


Lark
Novice

Jan 4, 2004, 6:21 PM

Post #11 of 26 (5137 views)
Re: [Recall] server change causing error messages [In reply to] Can't Post

i tryed the following code with no results, it still did the same thing


Code
$|++;  
use CGI::Carp qw(fatalsToBrowser);




and i left the link this way


Code
 $guestbook_file = '../guestbook/guestbook.html';  





anyother suggetions?


davorg
Thaumaturge / Moderator

Jan 7, 2004, 2:39 AM

Post #12 of 26 (5127 views)
Re: [Lark] server change causing error messages [In reply to] Can't Post


In Reply To
anyother suggetions?


Only the same one I've made twice and that you've ignored both times.

What happened when you ran it from the command line (on your new server)?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Lark
Novice

Jan 7, 2004, 4:58 AM

Post #13 of 26 (5124 views)
Re: [davorg] server change causing error messages [In reply to] Can't Post

oh i'm sorry davorg, well, i ran it from the command line of my home pc, and it runs flawlessly! what does that mean? if server has perl, and perl directory is correct on server, is my link bad?

i am not sure how to run it from the command line of the server! i'll need to research that one...


(This post was edited by Lark on Jan 7, 2004, 4:59 AM)


Lark
Novice

Jan 7, 2004, 6:12 AM

Post #14 of 26 (5121 views)
Re: [davorg] server change causing error messages [In reply to] Can't Post

davorg, i can't find "the command line" for my NEW server! it isn't a choice from the admin menu... but this i do know


Quote


Web Document Path

/var/www/html

CGI Document Path /var/www/cgi-bin



that is what it says on the admin screen...remember this NEW server isn't one of mine...i purchased webspace from an outside source and transferred my files to it



now, there are 3 files in this particular scenerio...

1] addguest.html (the input form)

2] guestbook.pl (da, the perl script)

3] guesbook.html ( the display page)



now i know for sure that the 'addguest.html' page calls up the guestbook.pl script, but that's is where it stops working...

i do not know how to run the script from the server command line...can you help me out? i do know that the apache server is runnning WEBppliance Pro 3.5.20-9 does that help?


(This post was edited by Lark on Jan 7, 2004, 8:48 AM)


James
Troll

Jan 7, 2004, 10:45 AM

Post #15 of 26 (5117 views)
Re: [Lark] server change causing error messages [In reply to] Can't Post


In Reply To
davorg, i can't find "the command line" for my NEW server! it isn't a choice from the admin menu... but this i do know

i do not know how to run the script from the server command line...can you help me out? i do know that the apache server is runnning WEBppliance Pro 3.5.20-9 does that help?



WEBppliance is Ensim's web-based control panel, which doesn't have anything to do with the command line. You'd access the command line using telnet or secure shell (SSH), assuming you have permission to use that on your server.

You can find out if you have that permission, by clicking on the Services link from your Site Administration panel. If you see "OpenSSH Secure Shell" and/or "Telnet" in your list of available services, you have the corresponding access. If you do have shell access, the server administrator will be able to provide the information you need to connect; or look at the "Accessing and using services" section of the WEBppliance Help file.

James


Lark
Novice

Jan 7, 2004, 10:54 AM

Post #16 of 26 (5113 views)
Re: [James] server change causing error messages [In reply to] Can't Post

i have both, but am ignorant in how to use them! please teach me, i learn super fast


James
Troll

Jan 7, 2004, 12:11 PM

Post #17 of 26 (5107 views)
Re: [Lark] server change causing error messages [In reply to] Can't Post


In Reply To
i have both, but am ignorant in how to use them! please teach me, i learn super fast



I'd start by reading the link I provided here and above to figure out how to connect and what to do once you're connected. Use the Basic Unix Commands (particlularly the cd command) to navigate to the directory your script is in. Then type something like this:


Code
perl -w guestbook.pl



(I don't make any representations that that's the best or even the right way to do it -- but that's the way I'd do it.)

But really, given Dave's earlier assessment of the script you're trying to run -- "That is an extremely badly written script and I'd never let it anywhere near a web server that I was running" -- you'd probably be much better off to forget this one entirely, go find a better one, and start from scratch. nms has a Guestbook script that I think Dave and the other gurus will approve of.

James


Lark
Novice

Jan 7, 2004, 12:37 PM

Post #18 of 26 (5105 views)
Re: [James] server change causing error messages [In reply to] Can't Post

i want the script to talk the specific input information and place it in the exact format already established...will their guestbook scripts do this?

also, i downloaded telnet stuff, doen'st do me any good, b/c i have never seen a unix, used a unix, etc...


Jasmine
Administrator

Jan 7, 2004, 12:40 PM

Post #19 of 26 (5103 views)
Re: [Lark] server change causing error messages [In reply to] Can't Post

If you look at James' reply, he gave you a url that will show you what you need and how to do it.


Lark
Novice

Jan 7, 2004, 3:25 PM

Post #20 of 26 (5089 views)
Re: [Jasmine] server change causing error messages [In reply to] Can't Post

i deleted a few of my posts prior to this b/c they are irrelavent now,...when i logged into the secure shell and used the ls command, i noticed that there was a cgi folder AND a perl folder... i had originally placed the guestbook.pl script in the cgi folder (assuming it was the cgi-bin); however, when i saw the perl folder, i moved the script to it and ran it again, guess what, it worked! just one problem left... you might have noticed some 'mail' stuff that was disabled in the script, well i originally wrote that in when i downloaded a demo of sendmail for my home server, and after the month was up i dicontinued using it (instead of paying for it)...but the new server has the sendmail program on it in the following directory: usr/sbin/sendmail

how would i modify my script to run the mail feature again?


(This post was edited by Lark on Jan 7, 2004, 8:05 PM)


davorg
Thaumaturge / Moderator

Jan 9, 2004, 4:34 AM

Post #21 of 26 (5082 views)
Re: [Lark] server change causing error messages [In reply to] Can't Post


In Reply To
when i logged into the secure shell and used the ls command, i noticed that there was a cgi folder AND a perl folder... i had originally placed the guestbook.pl script in the cgi folder (assuming it was the cgi-bin); however, when i saw the perl folder, i moved the script to it and ran it again, guess what, it worked!


I'd guess that you're now running under mod_perl as an Apache::Registry script. If it works, that's fine, but just bear in mind that you're no longer running straight CGI.


In Reply To
just one problem left... you might have noticed some 'mail' stuff that was disabled in the script, well i originally wrote that in when i downloaded a demo of sendmail for my home server, and after the month was up i dicontinued using it (instead of paying for it)...but the new server has the sendmail program on it in the following directory: usr/sbin/sendmail

how would i modify my script to run the mail feature again?


Find the line that mentions "sendmail" and replace that with /usr/sbin/sendmail. Then uncomment all of the stuff that you'd commented out.

I'm interested to know why you're ignoring all the good advice to scrap the script and start again with something a little better.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Lark
Novice

Jan 9, 2004, 7:49 AM

Post #22 of 26 (5081 views)
Re: [davorg] server change causing error messages [In reply to] Can't Post

thanks, i'll try that and reply again later with the results...

now to address the reason i am ignoring the advice to scrap the script and get a new one...

PRIDE -- This was my first script, my only script, I had to read a dadgom Perl textbook from a library to figure that stuff out, and after about 6 days working straight on it, it finally worked... i don't care if it is the worst looking piece of crappy code out there, it is my baby! LOL just being a protective parent... besides, it does exactly what i want it too, nothing more, nothing less... also, i enjoy the learning process, i will definitely take offense (a good thing) to folks calling it crap, and will in return research why, and possible make inprovements

i do appreciate all the help, though!


davorg
Thaumaturge / Moderator

Jan 9, 2004, 8:28 AM

Post #23 of 26 (5080 views)
Re: [Lark] server change causing error messages [In reply to] Can't Post

Oh, sorry. I didn't realise that you wrote it yourself :)

What book was it that you read? It looks like it's full of very bad advice. All copies need to be tracked down and burnt!

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Lark
Novice

Jan 9, 2004, 8:51 AM

Post #24 of 26 (5078 views)
Re: [davorg] server change causing error messages [In reply to] Can't Post

i checked out the book from the University of Central Arkansas library...that may explain it!LOL

and the MAIL section of the script is working as well, so that concludes all aspects of these posts! much thanks to davorg (who, by the way, has a very cool website. i love the warning labels section!), and thanks to every other person that posted suggestions...sometimes dumbluck will solve the problem! i never would have thought not to put the perl file in the cgi-bin...i even talked to the tech guy for the server, he ran a test.cgi, but wouldn't help with my script b/c they didn't write it! dumb butt! he could have told me then the perl script was in the wrong directory! also thanks to the one who made the suggestion of running it from the command line of the server using secure shell...that is when i saw the perl-bin...

Please add your post to my guestbook, I would be HONORED!

http://www.MrLarkins.com


(This post was edited by Lark on Jan 9, 2004, 9:01 AM)


davorg
Thaumaturge / Moderator

Jan 9, 2004, 9:04 AM

Post #25 of 26 (5074 views)
Re: [Lark] server change causing error messages [In reply to] Can't Post


In Reply To
he could have told me then the perl script was in the wrong directory


You weren't putting it in the wrong directory. The cgi-bin directory is the right directory for CGI programs. The perl directory is for mod_perl programs. There's still an unresolved problem as to why your program works under mod_perl but not as a CGI program.

But I guess that as it works under mod_perl, you don't need to find out what's wrong when running it as a CGI program.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

First page Previous page 1 2 Next page Last page  View All
 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives