在PHP中,通过header函数可以设置HTTP头,这对于控制网页的缓存、重定向和输出内容非常有用。本文将为您详细介绍如何使用header函数来设置HTTP头,并提供相应的源代码示例。
- 设置Content-Type头
Content-Type头用于指定服务器响应的内容类型。通过设置Content-Type头,我们可以告诉浏览器如何解析返回的数据。下面是一个设置Content-Type头的示例:
<?php
header("Content-Type: text/html; charset=UTF-8");
?>
在上述示例中,我们将Content-Type头设置为"text/html",并指定字符集为UTF-