php header功能的使用
时间:2023-11-15 09:25:26
header() 函数向客户端发送原始的 HTTP 报头。
<?php
//200 正常状态
header('HTTP/1.1 200 OK');
// 301 永久重定向,记得在后面要加重定向地址 Location:$url
header('HTTP/1.1 301 Moved Permanently');
// 重定向,其实就是302 暂时重定向
header('Location: http://www.maiyoule.com/');
// 设置页面304 没有修改
header('HTTP/1.1 304 Not Modified');
// 显示登录框,
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="登录信息"');
echo '显示的信息!';
// 403 禁止访问
header('HTTP/1.1 403 Forbidden');
// 404 错误
header('HTTP/1.1 404 Not Found');
// 500 服务器错误
header('HTTP/1.1 500 Internal Server Error');
// 3秒后重定向指定地址(也就是刷新到新页面与 <meta http-equiv="refresh" content="10;https://www.jb51.net/ /> 相同)
header('Refresh: 3; url=https://www.jb51.net/');
echo '10后跳转到https://www.jb51.net';
// 重写 X-Powered-By 值
header('X-Powered-By: PHP/5.3.0');
header('X-Powered-By: Brain/0.6b');
//设置上下文语言
header('Content-language: en');
// 设置页面最后修改时间(多用于防缓存)
$time = time() - 60; //建议使用filetime函数来设置页面缓存时间
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
// 设置内容长度
header('Content-Length: 39344');
// 设置头文件类型,可以用于流文件或者文件下载
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');
readfile('example.zip');//读取文件到客户端
//禁用页面缓存
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Pragma: no-cache');
//设置页面头信息
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain');
header('Content-Type: image/jpeg');
header('Content-Type: application/zip');
header('Content-Type: application/pdf');
header('Content-Type: audio/mpeg');
header('Content-Type: application/x-shockwave-flash');
//.... 至于Content-Type 的值 可以去查查 w3c 的文档库,那里很丰富
?>
标签:php,header,header状态
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python3.5集合及其常见运算实例详解
2023-04-25 04:04:33
django框架使用orm实现批量更新数据的方法
2023-08-11 04:48:25
asp图片加水印的功能代码
2011-02-05 11:02:00
从Web查询数据库之PHP与MySQL篇
2009-09-19 16:58:00
Mysql 数据库常用备份方法和注意事项
2024-01-17 15:43:25
python使用re模块爬取豆瓣Top250电影
2023-10-11 17:28:38
![](https://img.aspxhome.com/file/2023/0/82650_0s.png)
python 使用socket传输图片视频等文件的实现方式
2022-11-12 11:55:37
GoLang 中的随机数的示例代码
2024-04-26 17:16:51
pytorch中的squeeze函数、cat函数使用
2022-03-27 14:32:24
使用遗传算法求二元函数的最小值
2022-07-29 09:13:37
![](https://img.aspxhome.com/file/2023/5/93775_0s.jpg)
asp检测是否为中文字符函数
2011-04-07 11:19:00
opencv3/C++实现视频读取、视频写入
2021-12-17 10:01:16
![](https://img.aspxhome.com/file/2023/1/133261_0s.jpg)
php 参数过滤、数据过滤详解
2023-11-17 17:36:56
百度百科的图片轮播代码
2009-05-06 12:58:00
pandas按若干个列的组合条件筛选数据的方法
2023-10-27 03:49:07
![](https://img.aspxhome.com/file/2023/6/109566_0s.jpg)
python 已知三条边求三角形的角度案例
2022-09-06 01:18:41
什么是Ajax及Ajax的优势
2007-09-07 09:56:00
![](https://img.aspxhome.com/file/UploadPic/up/2007091821580144.jpg)
从开发人员角度看IE8的开发新特性
2010-02-26 10:48:00
MySQL左联多表查询where条件写法示例
2024-01-14 08:44:43
![](https://img.aspxhome.com/file/2023/1/109831_0s.jpg)
CSS雪碧:要还是不要?
2009-11-16 13:01:00