Samn has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: Unexpected "text/plain" output with cgi
by janjan (Beadle) on Nov 13, 2002 at 17:15 UTC
    You can always explicitly send a header -- it doesn't look like you're doing that. CGI.pm makes it easy:
    print $q->header('text/html');
    perldoc CGI for more on this. Or, you can send your header manually:
    print "Content-type: text/html\n\n";
    Other than that, I'm not sure why the Mozilla browsers aren't rendering the code. Perhaps posting the contents of the $page variable or the *.rs files would help.
Re: Unexpected "text/plain" output with cgi
by enoch (Chaplain) on Nov 13, 2002 at 17:48 UTC
    Since no one has pointed it out, yet, you really really, really do not want to do:
    if ($page) { &$page; }
    What if someone (and, don't do this) passed in the URL http://www.robotskull.com/cgi-bin/index.cgi?page=kittens;`rm -rf /etc` (or worse). A better way would be to:
    if($page) { SWITCH: { &kitten, last SWITCH if($page eq 'kitten'); &foo, last SWITCH if($page eq 'foo'); &bar, last SWITCH if($page eq 'bar'); . . . print STDERR "invalid CGI parameter", last SWITCH; } }

    Enoch
Re: Unexpected "text/plain" output with cgi
by iburrell (Chaplain) on Nov 13, 2002 at 17:22 UTC
    You need to send back the HTTP header before sending any HTML. You may be doing this but it isn't happening for the code path that prints the secondary pages. Specifically, you need to set Content-Type header to text/html. Otherwise, Apache sets the default to text/plain which is what is showing up on your link above. The easiest way to do this is with the CGI.pm module's header method.
    use CGI; print header;

    IE is broken and recognizes the document is HTML and displays it as a web page. Mozilla is behaving properly and shows the HTML as plaintext like the server told it to.

      I guess you meant something like
      use CGI qw(:standard);
      Otherwise the header function won't be exported into your namespace.


      $|=$_="1g2i1u1l2i4e2n0k",map{print"\7",chop;select$,,$,,$,,$_/7}m{..}g

Re: Unexpected "text/plain" output with cgi
by fglock (Vicar) on Nov 13, 2002 at 17:53 UTC

    Interesting. Your HEAD is obviously wrong, maybe caused by something in your "*.rs" line.

    It shows:

    200 OK Connection: close Date: Wed, 13 Nov 2002 17:50:18 GMT Server: Apache/1.3.26 (Unix) PHP/4.2.2 mod_gzip/1.3.19.1a Content-Type: text/plain Client-Date: Wed, 13 Nov 2002 16:36:49 GMT Client-Junk: loading test.rs<br>loading admin.rs<br>loading cleanmails +.rs<br>loading testtest.rs<br>loading user.rs<br>loading robocon.rs<b +r>loading gator.rs<br>loading camn.rs<br>loading weather.rs<br>loadin +g getdef.rs<br>loading development.rs<br>loading profile.rs<br>loadin +g mail.rs<br>loading vocab.rs<br>loading rfc.rs<br>loading story.rs<b +r>loading test3.rs<br>loading admin_field_edit.rs<br>loading glossary +.rs<br>loading fack.rs<br>loading everbox.rs<br>loading emo.rs<br>loa +ding kittens.rs<br>loading icons.rs<br>loading gazelle.rs<br>loading +create.rs<br>loading comments.rs<br>loading candy.rs<br>loading babbl +e.rs<br>loading meta_change.rs<br>loading meta_display.rs<br>loading +meta_base.rs<br>loading meta_archive.rs<br>loading metapad.rs<br>load +ing login.rs<br>loading space.rs<br>loading links.rs<br>loading truth +.rs<br>loading shirtninja.rs<br>loading post.rs<br>loading modules.rs +<br>loading stayfresh.rs<br>loading titles.rs<br>loading update_syste +m_notice.rs<br>loading user_list.rs<br>loading raim.rs<br>loading ski +ns.rs<br>loading scratchpad.rs<br>loading notes.rs<br>loading news.rs +<br>loading titlechange.rs<br>loading ropasc.rs<br>loading send_note. +rs<br>loading suggest.rs<br>loading preview_module.rs<br>loading scor +e.rs<br>loading skullbot.rs<br>loading jessika_cam.rs<br>loading jess +ika.rs<br>loading printtabs.rs<br>loading chrisemails.rs<br>loading j +ournal.rs<br>loading source.rs<br>loading school.rs<br>loading thetea +m.rs<br>loading system_notice.rs<br>Content-type: text/html Client-Response-Num: 1
212653
by Samn (Monk) on Nov 13, 2002 at 18:00 UTC
    Re: Unexpected "text/plain" output with cgi
    by Mr. Muskrat (Canon) on Nov 13, 2002 at 17:19 UTC

      If it is transmitted as a text document, then your cgi script is setting a plain text content-type header...

      Show us the real code please, not psueodocode.