PHP header() 函数
来源:互联网 发布:淘宝网今日特惠 编辑:程序博客网 时间:2024/05/22 16:26
定义和用法
header() 函数向客户端发送原始的 HTTP 报头。
认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数(在 PHP 4 以及更高的版本中,您可以使用输出缓存来解决此问题):
<html><?php// 结果出错// 在调用 header() 之前已存在输出header('Location: http://www.example.com/');
?>
语法
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。
- 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()函数详解
- QuartusII警告信息解析
- 状态机的两种写法
- verilogHDL精粹
- Android transitions- slide in and slide out
- Tomcat全攻略
- PHP header() 函数
- 六.web service
- ASP.NET的五大数据控件(GridView,DataList,Repeater ,DetailsView,FormView)浅谈
- 从一直没实现的计划想到的
- mini2440的LEDS驱动程序和测试程序详解
- 页面抓取特定链接
- NetSNS二次开发系列1--文章系列简介
- 编程修养(2)
- 设计模式之 -- Decorator pattern (修饰模式)