PHP header函数设置http报文头(设置头部域)
时间:2023年11月24日
/来源:网络
/编辑:佚名
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.baidu.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.baidu.com/');
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.baidu.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.baidu.com/');
新闻资讯 更多
- 【建站知识】查询nginx日志状态码大于400的请求并打印整行04-03
- 【建站知识】Python中的logger和handler到底是个什么?04-03
- 【建站知识】python3拉勾网爬虫之(您操作太频繁,请稍后访问)04-03
- 【建站知识】xpath 获取meta里的keywords及description的方法04-03
- 【建站知识】python向上取整以50为界04-03
- 【建站知识】scrapy xpath遇见乱码解决04-03
- 【建站知识】scrapy爬取后中文乱码,解决word转为html 时cp1252编码问题04-03
- 【建站知识】scrapy采集—爬取中文乱码,gb2312转为utf-804-03