是 header('Content-Type:text/plain');有必要吗?

Is header(#39;Content-Type:text/plain#39;); necessary at all?(是 header(Content-Type:text/plain);有必要吗?)
本文介绍了是 header('Content-Type:text/plain');有必要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还没有看到有或没有这个头部信息的任何区别.

I didn't see any difference with or without this head information yet.

推荐答案

定义必要".

如果您希望浏览器知道文件的类型是什么,这是必要的.如果您不覆盖它,PHP 会自动将 Content-Type 标头设置为 text/html,因此您的浏览器会将其视为不包含任何 HTML 的 HTML 文件.如果您的输出包含任何 HTML,您会看到非常不同的结果.如果您要发送:

It is necessary if you want the browser to know what the type of the file is. PHP automatically sets the Content-Type header to text/html if you don't override it so your browser is treating it as an HTML file that doesn't contain any HTML. If your output contained any HTML you'd see very different outcomes. If you were to send:

<b><i>test</i></b>

内容类型:文本/html;charset=UTF-8 将以粗体和斜体显示在浏览器文本中:

Content-Type: text/html; charset=UTF-8 would display in the browser text in bold and italics:

✅ 好的

Content-Type: text/plain;charset=UTF-8 会像这样在浏览器中显示:

whereas Content-Type: text/plain; charset=UTF-8 would display in the browser like this:

<b><i>✅ OK</i></b>

TLDR 版本: 如果你真的只输出纯文本,没有像 <> 这样的特殊字符,那么它不会真的很重要,但它错了.

TLDR Version: If you really are only outputing plain text with no special characters like < or > then it doesn't really matter, but it IS wrong.

这篇关于是 header('Content-Type:text/plain');有必要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)