-1

When I set content type at the top of a simple PHP script:

<?php
    header('Content-type: text/plain; charset=utf-8');
    echo "<P>this is a paragraph</p>";
?>

The page is served as HTML source code (not php, just the HTML).

<P>this is a paragraph</p>

Why is that?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
a coder
  • 7,530
  • 20
  • 84
  • 131

2 Answers2

2

I wouldn't expecting anything else when serving the content as text/plain. If you want the browser to interpret this as HTML, change the header to text/html.

Bartosz Zasada
  • 3,762
  • 2
  • 19
  • 25
  • this was a simple type-o in my code, and this answer means I can't delete my mistake and reduce clutter on SO. – a coder Jan 25 '17 at 15:44
0

Php is server-side: It will execute and send what you tell it to send.
Sending the content-type header won't affect the php output, but will affect how the client evaluates it.
In your case, even if you echo <script>alert('test');</script>, it won't be considered javascript by the client but only text, same goes for all html tags.

Antony
  • 1,253
  • 11
  • 19
  • this was a simple type-o in my code, and this answer means I can't delete my mistake and reduce clutter on SO. – a coder Jan 25 '17 at 15:44