Forum Moderators: coopster & phranque

Message Too Old, No Replies

CGI Issue - Displaying only HTML

         

hirerobhere

11:03 pm on Jan 20, 2008 (gmt 0)

10+ Year Member



A client's site was migrated and all of the CGI scripts were throwing 500's. I checked and found that within some off them that the path was incorrect. I corrected this and the permissions but now they are all coming up as just text. It's printing out all of the HTML that is supposed to be being displayed. I checked the scripts over and nothing else seems to be off. Any ideas?

[edited by: phranque at 12:03 am (utc) on Jan. 21, 2008]
[edit reason] no URLs please [/edit]

hirerobhere

12:25 am on Jan 21, 2008 (gmt 0)

10+ Year Member



ok for some reason it is just not rendering the cgi in firefox. the site works in ie. weird. any ideas? i am setting the content-type but it still is being rendered as text/plain not text/html...

phranque

12:27 am on Jan 21, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], hirerobhere!

fyi, whenever you have a 500 you will also have a message in the server error log.

regarding your html-as-text problem, that typically means your script or server is not sending out the content type header first thing.

perl_diver

12:48 am on Jan 21, 2008 (gmt 0)

10+ Year Member



We will need to see some of the code, including where it prints the headers and what it prints. My guess is there is a small error in the header output.

hirerobhere

12:50 am on Jan 21, 2008 (gmt 0)

10+ Year Member



Thanks a bunch for your replies but I got it now. It was that the content-type wasn't output before everything else. Thanks again.

perl_diver

12:53 am on Jan 21, 2008 (gmt 0)

10+ Year Member



regarding your html-as-text problem, that typically means your script or server is not sending out the content type header first thing.

With a perl script that will generate a 500 error, not plain text output, unless they are using something like CGI::Carp which will print a header by default and the error message. HTML displayed as text should indicate that Firefox does not recognize the header or the header really is plain text instead of html.

rocknbil

4:46 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may still have a problem. perl_diver's solution will work, but if you aren't using carp, here is the scenario:

script process . . . okay
script process . . . okay
script process . . . ERROR
script process . . . okay
print "content-type: text/html\n\n";
output to browser

Most perl coders handle their errors like

[do something] or die("cannot do something!");

The die command will cause the script to terminate with an error to STDOUT - if run on the command line, this prints the message to the terminal. But if run from the web, it errors because it never got to the content-type.

So by moving the content-type to the top of the program, you can often miss errors, which is might be what you've done. The scripts run now, but they may still be dying somewhere inline.

I like to do

[do something] or &my_error_handler("Cannot do something");

where my_error_handler is just a small routine to print errors to the browser with a content-type. But that's another topic.

perl_diver

6:56 pm on Jan 22, 2008 (gmt 0)

10+ Year Member



I didn't provide any solutions....

phranque

1:21 am on Jan 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i think he was referring to:
using something like CGI::Carp which will print a header by default and the error message

perl_diver

8:27 am on Jan 23, 2008 (gmt 0)

10+ Year Member



ahh... you're probably correct phranque. Thanks.