www.webdeveloper.com
Results 1 to 7 of 7

Thread: Can't get CGI output to run in browser (Perl)

  1. #1
    Join Date
    Dec 2013
    Posts
    4

    Can't get CGI output to run in browser (Perl)

    I've written several CGI scripts using Perl and they run fine. Today I've been working on a server-side MP3 player that has me baffled. There are no errors being reported by Perl, and the output in my browser looks like good HTML. If I copy it into a new file and upload it, it runs perfectly. The problem is that the CGI output just sits there in my browser and doesn't run. When I turn on diagnostics in Firefox, it says:

    [15:56:19.954] The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature. @ http://theinfosite.org/cgi-bin/autop...hid%20Retreats

    Here's the relevant portion:

    print<<QWERTYUIOP;

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <HTML>

    <HEAD>
    <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
    <TITLE>1001 Verses</TITLE>
    <META NAME="DESCRIPTION" CONTENT="1001 Verses from Arabian Nights Mardrus-Mathers translation">
    <STYLE TYPE="text/css">
    <!--
    P { color: #000080 }
    TD P { color: #000080 }
    H1 { color: #000080 }
    A:visited { color: #ff00ff }
    -->
    </STYLE>
    </HEAD>

    <BODY LANG="en-US" TEXT="#000080" VLINK="#ff00ff" BACKGROUND="http://theinfosite.org/image2.jpg" DIR="LTR">
    <P ALIGN=CENTER><FONT SIZE=10<B>1001 Verses</B></FONT>
    <P ALIGN=CENTER><FONT SIZE=5<B>$poem</B></FONT><br>
    <p ALIGN=CENTER><audio SRC="http://theinfosite.org/1001/Book 16/$poem.mp3\" controls autoplay>;
    Your browser does not support the audio element </audio></p>
    </BODY>

    </HTML>
    QWERTYUIOP

    And here's the output:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <HTML>

    <HEAD>
    <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
    <TITLE>1001 Verses</TITLE>
    <META NAME="DESCRIPTION" CONTENT="1001 Verses from Arabian Nights Mardrus-Mathers translation">
    <STYLE TYPE="text/css">
    <!--
    P { color: #000080 }
    TD P { color: #000080 }
    H1 { color: #000080 }
    A:visited { color: #ff00ff }
    -->
    </STYLE>
    </HEAD>

    <BODY LANG="en-US" TEXT="#000080" VLINK="#ff00ff" BACKGROUND="http://theinfosite.org/image2.jpg" DIR="LTR">
    <P ALIGN=CENTER><FONT SIZE=10<B>1001 Verses</B></FONT>
    <P ALIGN=CENTER><FONT SIZE=5<B>Al-Rachid Retreats</B></FONT><br>
    <p ALIGN=CENTER><audio SRC="http://theinfosite.org/1001/Book 16/Al-Rachid Retreats.mp3" controls autoplay>;
    Your browser does not support the audio element </audio></p>
    </BODY>

    </HTML>

    Thanks for any help you can give!

  2. #2
    Join Date
    Oct 2007
    Location
    Vienna, Austria
    Posts
    393
    It's a content-type issue. The server says this in the HTTP headers: Content-Type: text/plain. So check where the headers are set and change the content type to text/html.

  3. #3
    Join Date
    Dec 2013
    Posts
    4
    Quote Originally Posted by Sixtease View Post
    It's a content-type issue. The server says this in the HTTP headers: Content-Type: text/plain. So check where the headers are set and change the content type to text/html.
    Er... hate to be dumb but I can't see anyplace in the output where it says text/plain instead of text/html. If you see it, would you please point it out to me?

  4. #4
    Join Date
    Oct 2007
    Location
    Vienna, Austria
    Posts
    393
    The whole response consists of HTTP headers and then the HTTP body. The HTTP body is a HTML document, which consists again of HTML head and HTML body but that's another story. The headers are set somewhere else in the script, in a part that's not shown in your post. But when you do an ajax request, you see in the headers that the content type is text/plain.

  5. #5
    Join Date
    Dec 2013
    Posts
    4
    Here's the top part of my script (the rest I posted above):
    #!/usr/local/bin/perl

    BEGIN {
    my $b__dir =
    ( -d '/home1/theinfp0/perl'
    ? '/home1/theinfp0/perl'
    : ( getpwuid($>) )[7] . '/perl' );
    unshift @INC, $b__dir . '5/lib/perl5',
    $b__dir . '5/lib/perl5/x86_64-linux-thread-multi',
    map { $b__dir . $_ } @INC;
    }

    use CGI;
    my $cgi = new CGI;

    use Mail::Sendmail;

    use CGI::Carp qw(set_die_handler);

    BEGIN {

    sub handle_errors {
    my $msg = shift;
    sendmail(
    From => 'info@theinfosite.com',
    To => 'jmrhide-theinfosite@yahoo.com',
    Subject => '1001 Verses Error',
    Message => $msg,
    );
    }
    set_die_handler( \&handle_errors );
    }

    my ($poem);

    $poem = $cgi->param('poem');

    Can you point to the problem for me?

  6. #6
    Join Date
    May 2004
    Location
    chennai, tamil nadu, India
    Posts
    451
    Code:
    print $cgi->header('text/html');

  7. #7
    Join Date
    Dec 2013
    Posts
    4
    Quote Originally Posted by chrisranjana View Post
    Code:
    print $cgi->header('text/html');
    Thanks! The output looks exactly the same but now it runs as designed.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles