PHP header() 函数
来源:互联网 发布:ncp1337p各脚电压数据 编辑:程序博客网 时间:2024/05/22 06:34
定义和用法
header() 函数向客户端发送原始的 HTTP 报头。
认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数(在 PHP 4 以及更高的版本中,您可以使用输出缓存来解决此问题):
<html><?php// 结果出错// 在调用 header() 之前已存在输出header('Location: http://www.example.com/');?>
语法
header(string,replace,http_response_code)
header(string,replace,http_response_code)
可选。指示该报头是否替换之前的报头,或添加第二个报头。
默认是 true(替换)。false(允许相同类型的多个报头)。
http_response_code可选。把 HTTP 响应代码强制为指定的值。(PHP 4 以及更高版本可用)提示和注释
注释:从 PHP 4.4 之后,该函数防止一次发送多个报头。这是对头部注入攻击的保护措施。
例子
例子 1
<?php// Date in the pastheader("Expires: Mon, 26 Jul 1997 05:00:00 GMT");header("Cache-Control: no-cache");header("Pragma: no-cache");?><html><body>......
注释:用户可能会设置一些选项来更改浏览器的默认缓存设置。通过发送上面的报头,您可以覆盖任何这些设置,强制浏览器不进行缓存!
例子 2
提示用户保存一个生成的 PDF 文件(Content-Disposition 报头用于提供一个推荐的文件名,并强制浏览器显示保存对话框):
<?phpheader("Content-type:application/pdf");// 文件将被称为 downloaded.pdfheader("Content-Disposition:attachment;filename='downloaded.pdf'");// PDF 源在 original.pdf 中readfile("original.pdf");?><html><body>......
注释:微软 IE 5.5 存在一个阻止以上机制的 bug。通过升级为 Service Pack 2 或更高的版本,可以解决该 bug。
参考链接:http://www.w3school.com.cn/php/func_http_header.asp
阅读全文
0 0
- php header()函数使用说明
- PHP header() 函数
- PHP header() 函数
- PHP header() 函数
- php header() 函数详解
- PHP函数:header()
- php header()函数
- PHP 中 header()函数
- php header函数详解
- PHP header() 函数
- php header函数详解
- PHP header() 函数
- PHP header() 函数
- PHP header函数
- php header()函数使用说明
- php函数header作用:
- PHP header()函数详解
- PHP header()函数详解
- 【问题集】这是什么编码错误?
- POJ 1287 Networking 笔记
- Sublime Text插件的安装及使用心得
- ElasticSearch原理入门
- 数据类型
- PHP header() 函数
- C++之类模板详解(一)
- A.Bit++
- 左连接和右连接
- 第六届蓝桥杯决赛真题 04 穿越雷区(dfs || bfs)
- 阿里云服务器Svn-Server无法连接,阿里云服务器SVNServer配置
- DB Format show
- oracle 和mysql使用上的区别
- 寻找数组中的主元素