Reputation: 1209
I have a .pl perl script on my website. I want the code to print out as if it were a html page rather then perl page. My code is bellow, and bellow that highlight is what I 'see' when I visit the page. What I'd like to see when I visit the page is just 'Hello'. not all the tags. (For purposes of being online I made the actual html code simply 'Hello' rather then the actual html that would be on my page. Although it server the same purpose...
What the .pl code is:
#!/usr/bin/perl
use v5.10;
use CGI;
$q = CGI->new;
print $q->header("text/plain");
$html_template = qq{<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p>Hello</p>
</body>
</html>
};
print $q->header;
print $html_template;
What It prints out when I visit the page:
Content-Type: text/html; charset=ISO-8859-1
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p>Hello</p>
</body>
</html>
What I want it to print out:
Hello
Upvotes: 1
Views: 6141
Reputation: 385897
Remove the print $q->header("text/plain");
.
Your code boils down to
print $q->header("text/plain");
print $q->header;
print $html_template;
You send a header saying what follows is text data. The browser happily displays the remainder of the response (a second header and some HTML) as text data.
You should be doing
print $q->header("text/html");
print $html_template;
which is also achieved using
print $q->header;
print $html_template;
Upvotes: 4
Reputation: 887469
print $q->header("text/plain");
If you tell the browser that you're sending text rather than HTML, sane browsers will believe you and display plain text.
Upvotes: 7