Forum Moderators: coopster & phranque

Message Too Old, No Replies

CGI script shows html tags on browser

         

rominosj

5:01 pm on Nov 2, 2015 (gmt 0)

10+ Year Member



Hello,

I am using WAMP to practice with CGI and Perl.

My problem is when I execute the cgi script, Firefox shows it as HTML source code, but I am not in page source view.

Below is the code I am using:


#!D:/perl/perl/bin/perl.exe
#use strict;
#use diagnostics;
#use CGI::Carp 'fatalsToBrowser';
#use CGI qw(-debug);
print "Content-type: text/plain\n\n";
print "<html><head><title>Hello World</title></head>\n";
print "<body>\n";
print "<h2>Hello, world!</h2>\n";
print "</body></html>\n";


This is what Firefox shows:

<html><head><title>Hello World</title></head>
<body>
<h2>Hello, world!</h2>
</body></html>


I searched on Google, and found that I should add "AddType text/html .html .htm", but that did not help either.

Any idea why this could be happening?

Thanks!

Brett_Tabke

5:33 pm on Nov 2, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



This code works on my machine:

#!/usr/bin/perl

print "Content-type: text/html\n\n";
print "<html><head><title>Hello World</title></head>\n";
print "<body>\n";
print "<h2>Hello, world!</h2>\n";
print "</body></html>\n";

Yes, if you see html tags, then the server is sending "test/plain" to the browser and the browser is showing pure text.

Switch it to:

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

and it should work great.

rominosj

1:58 am on Nov 3, 2015 (gmt 0)

10+ Year Member



Thanks Brett!

eurohttp

9:14 pm on Jan 17, 2016 (gmt 0)

10+ Year Member



Are you sure you have Perl or Strawberry Perl installed?