PHP header函数设置http报文头(设置头部域)

PHP HTTP 简介:  
HTTP 函数允许您在其他输出被发送之前,对由 Web 服务器发送到浏览器的信息进行操作。

PHP 5 HTTP 函数:
header()     向客户端发送原始的 HTTP 报头。
headers_list()     返回已发送的(或待发送的)响应头部的一个列表。
headers_sent()     检查 HTTP 报头是否发送/已发送到何处。
setcookie()     定义与 HTTP 报头的其余部分一共发送的 cookie。
setrawcookie()     定义与 HTTP 报头的其余部分一共发送的 cookie(不进行 URL 编码)。

header()函数的定义和用法:  

header() 函数向客户端发送原始的 HTTP 报头。

认识到一点很重要,即必须在  任何实际的输出被发送之前调用 header() 函数(在 PHP 4 以及更高的版本中,您可以使用输出缓存来解决此问题):  

<html>
<?php
// 结果出错
// 在调用 header() 之前已存在输出
header('Location: http://www.example.com/');
?>

//设置内容长度
header('Content-Length: 1234');

//XML
header('Content-type: text/xml');

//JSON
header('Content-type: application/json');

//CSS
header('Content-type: text/css');

//定义编码
header( 'Content-Type:text/html;charset=utf-8 ');

//转到一个新地址
header('Location: http://www.example.org/');

参考:http://www.tuicool.com/articles/AR7fIv

  

设置头部域

原文地址:https://www.cnblogs.com/wangyuman26/p/6216717.html