header() 函数向客户端发送原始的 HTTP 报头。
例子 1
//页面跳转
header('Location:
);
例子 2
//提示用户保存一个生成的 PDF 文件(Content-Disposition 报头用于提供一个推荐的文件名,并强制浏览器显示保存对话框)
header("Content-type:application/pdf");
// 文件将被称为 downloaded.pdf
header("Content-Disposition:attachment;filename='downloaded.pdf'");
// PDF 源在 original.pdf 中
readfile("original.pdf");
例子 3
//用户可能会设置一些选项来更改浏览器的默认缓存设置。通过发送上面的报头,您可以覆盖任何这些设置,强制浏览器不进行缓存!
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
1、函数描述:
header() 函数向客户端发送原始的 HTTP 报头。
2、函数语法:
header(string,replace,http_response_code)
3、函数参数:
①string:必需。规定要发送的报头字符串;
②replace :可选。指示该报头是否替换之前的报头,或添加第二个报头。默认是 true(替换)。false(允许相同类型的多个报头);
③http_response_code:可选。把 HTTP 响应代码强制为指定的值。
4、函数举例:
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>
header的用法
模拟WEB服务器的一些输出。
比如:模拟404(找不到网页的输出)
header("HTTP/1.0 404 Not Found");
在客户端就认为是这个文件不存在了
模拟页面跳转:
header("Location: abc.php");
就会直接跳转到 abc.php
(跟JS的跳转差不多)
。。。 还有很多,逐个试一试就知道的了.
设置http的响应头
标签:php,header,作用