Welcome to WebmasterWorld Guest from 100.26.182.28

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

CGI script shows html tags on browser

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

Junior Member from PE 

10+ Year Member

joined:Mar 28, 2004
posts: 145
votes: 1


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!
5:33 pm on Nov 2, 2015 (gmt 0)

Administrator from US 

WebmasterWorld Administrator brett_tabke is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 21, 1999
posts: 38255
votes: 113


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.
1:58 am on Nov 3, 2015 (gmt 0)

Junior Member from PE 

10+ Year Member

joined:Mar 28, 2004
posts:145
votes: 1


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

New User from ZW 

joined:Oct 1, 2014
posts:14
votes: 0


Are you sure you have Perl or Strawberry Perl installed?
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members