php header函数的常用http头设置


Posted in PHP onJune 25, 2015
//ok
header(‘HTTP/1.1 200 OK');
//设置一个404头:
header(‘HTTP/1.1 404 Not Found');
//设置地址被永久的重定向
header(‘HTTP/1.1 301 Moved Permanently');
//转到一个新地址
header(‘Location: http://www.example.org/‘);
//文件延迟转向:
header(‘Refresh: 10; url=http://www.example.org/‘);
print ‘You will be redirected in 10 seconds';
//当然,也可以使用html语法实现
// <meta http-equiv=”refresh” content=”10;http://www.example.org/ />
// override X-Powered-By: PHP:
header(‘X-Powered-By: PHP/4.4.0′);
header(‘X-Powered-By: Brain/0.6b');
//文档语言
header(‘Content-language: en');
//告诉浏览器最后一次修改时间
$time = time() ? 60; // or filemtime($fn), etc
header(‘Last-Modified: ‘.gmdate(‘D, d M Y H:i:s', $time).' GMT');
//告诉浏览器文档内容没有发生改变
header(‘HTTP/1.1 304 Not Modified');
//设置内容长度
header(‘Content-Length: 1234′);
//设置为一个下载类型
header(‘Content-Type: application/octet-stream');
header(‘Content-Disposition: attachment; filename=”example.zip”‘);
header(‘Content-Transfer-Encoding: binary');
// load the file to send:
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'); // Date in the past
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'); //JPG***
header(‘Content-Type: application/zip'); // ZIP文件
header(‘Content-Type: application/pdf'); // PDF文件
header(‘Content-Type: audio/mpeg'); // 音频文件
header(‘Content-Type: application/x-shockw**e-flash'); //Flash动画
//显示登陆对话框
header(‘HTTP/1.1 401 Unauthorized');
header(‘WWW-Authenticate: Basic realm=”Top Secret”‘);
print ‘Text that will be displayed if the user hits cancel or ‘;
print ‘enters wrong login data';
PHP 相关文章推荐
用PHP 4.2书写安全的脚本
Oct 09 PHP
海河写的 Discuz论坛帖子调用js的php代码
Aug 23 PHP
php5中类的学习
Mar 28 PHP
php的ajax框架xajax入门与试用介绍
Dec 19 PHP
深入php处理整数函数的详解
Jun 09 PHP
js和php邮箱地址验证的实现方法
Jan 09 PHP
将酷狗krc歌词解析并转换为lrc歌词php源码
Jun 20 PHP
五款PHP代码重构工具推荐
Oct 14 PHP
PHP实现抓取HTTPS内容
Dec 01 PHP
PHP响应post请求上传文件的方法
Dec 17 PHP
PHP邮件群发机实现代码
Feb 16 PHP
php获取ip及网址的简单方法(必看)
Apr 01 PHP
PHP里的单例类写法实例
Jun 25 #PHP
PHP合并数组+号和array_merge的区别
Jun 25 #PHP
PHP数组与对象之间使用递归实现转换的方法
Jun 24 #PHP
php计算多维数组中所有值总和的方法
Jun 24 #PHP
jquery获取多个checkbox的值异步提交给php的方法
Jun 24 #PHP
PHP将Excel导入数据库及数据库数据导出至Excel的方法
Jun 24 #PHP
php异常处理方法实例汇总
Jun 24 #PHP
You might like
使用PHP socke 向指定页面提交数据
2008/07/23 PHP
深入理解PHP之require/include顺序 推荐
2011/01/02 PHP
php中用memcached实现页面防刷新功能
2014/08/19 PHP
PHP使用Redis替代文件存储Session的方法
2017/02/15 PHP
浅谈Yii乐观锁的使用及原理
2017/07/25 PHP
PHP中__set()实例用法和基础讲解
2019/07/23 PHP
基于jQuery的左右滚动实现代码
2010/12/03 Javascript
Prototype源码浅析 Enumerable部分(二)
2012/01/18 Javascript
JS+CSS实现另类带提示效果的竖向导航菜单
2015/10/15 Javascript
原生js实现图片轮播特效
2015/12/18 Javascript
原生js实现移动端瀑布流式代码示例
2015/12/18 Javascript
谈谈JavaScript的New关键字
2016/08/26 Javascript
js在ie下打开对话窗口的方法小结
2016/10/24 Javascript
jQuery多选框选择数量限制方法
2017/02/08 Javascript
jQuery实现jQuery-form.js实现异步上传文件
2017/04/28 jQuery
原生JavaScrpit中异步请求Ajax实现方法
2017/11/03 Javascript
jQuery+CSS实现的table表格行列转置功能示例
2018/01/08 jQuery
bootstrap中日历范围选择插件daterangepicker的使用详解
2018/04/17 Javascript
[03:20]次级联赛厮杀超职业 现超级兵对拆世纪大战
2014/10/30 DOTA
[44:50]DOTA2上海特级锦标赛B组小组赛#2 VG VS Fnatic第二局
2016/02/26 DOTA
Python Web开发模板引擎优缺点总结
2014/05/06 Python
Python 模拟购物车的实例讲解
2017/09/11 Python
python使用KNN算法手写体识别
2018/02/01 Python
python使用json序列化datetime类型实例解析
2018/02/11 Python
Python3.5运算符操作实例详解
2019/04/25 Python
python3+PyQt5 自定义窗口部件--使用窗口部件样式表的方法
2019/06/26 Python
python数组循环处理方法
2019/08/26 Python
如何利用Python动态模拟太阳系运转
2020/09/04 Python
Python爬虫教程知识点总结
2020/10/19 Python
python 30行代码实现蚂蚁森林自动偷能量
2021/02/08 Python
css3动画效果抖动解决方法
2018/09/03 HTML / CSS
英国时尚高尔夫服装购物网站:Trendy Golf
2020/01/10 全球购物
俄罗斯达美乐比萨外送服务:Domino’s Pizza
2020/12/18 全球购物
销售主管岗位职责范本
2014/02/14 职场文书
卫生院艾滋病宣传活动小结
2014/07/09 职场文书
在职证明格式样本
2015/06/15 职场文书