php header()函数详细实用方法

admin 阅读:101 2024-03-01

header(string,replace,http_response_code)

string 必需,规定要发送的报头字符串.

replace 可选,指示该报头是否替换之前的报头,或添加第二个报头.

默认是 true(替换),false(允许相同类型的多个报头).

http_response_code 可选,把 http 响应代码强制为指定的值,(php 4 以及更高版本可用)

跳转:

header('location: http://www.codesou.cn/');发送http状态

header("status: 404 not found");

设置缓存:

header("cache-control: no-cache, must-revalidate"); // http/1.1

header("expires:sat,26 jul 1997 05:00:00 gmt");

利用header做文件下载功能:

header("content-type:application/pdf");// 文件将被称为 downloaded.pdf 
header("content-disposition:attachment;filename='downloaded.pdf'");// pdf 源在 original.pdf 中 
readfile("original.pdf"); 


声明

1、部分文章来源于网络,仅作为参考。
2、如果网站中图片和文字侵犯了您的版权,请联系1943759704@qq.com处理!