PHP header函数分析详解


Posted in PHP onAugust 06, 2011

在php语言中,header()这个函数很有用的,尤其在用到ajax时候,他会帮你解决一些意想不到的问题。下面是header的一些详细讲解。希望对phper有帮助

<?php 
// fix 404 pages: 
header('HTTP/1.1 200 OK'); 
// set 404 header: 
header('HTTP/1.1 404 Not Found'); 
// set Moved Permanently header (good for redrictions) 
// use with location header 
header('HTTP/1.1 301 Moved Permanently'); 
// redirect to a new location: 
header('Location: http://www.example.org/'); 
// redrict with delay: 
header('Refresh: 10; url=http://www.example.org/'); 
print 'You will be redirected in 10 seconds'; 
// you could also use the HTML syntax:// <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'); 
// content language (en = English) 
header('Content-language: en'); 
// last modified (good for caching) 
$time = time() ? 60; // or filemtime($fn), etc 
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); 
// header for telling the browser that the content 
// did not get changed 
header('HTTP/1.1 304 Not Modified'); 
// set content length (good for caching): 
header('Content-Length: 1234'); 
// Headers for an download: 
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'); 
// Disable caching of the current document: 
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 pastheader('Pragma: no-cache'); 
// set content type: 
header('Content-Type: text/html; charset=iso-8859-1'); 
header('Content-Type: text/html; charset=utf-8'); 
header('Content-Type: text/plain'); 
// plain text file 
header('Content-Type: image/jpeg'); 
// JPG picture 
header('Content-Type: application/zip'); 
// ZIP file 
header('Content-Type: application/pdf'); 
// PDF file 
header('Content-Type: audio/mpeg'); 
// Audio MPEG (MP3,…) file 
header('Content-Type: application/x-shockwave-flash'); 
// Flash animation// show sign in box 
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上的memcache和memcached两个pecl库
Mar 29 PHP
PHP Undefined index报错的修复方法
Jul 17 PHP
ThinkPHP模板判断输出Empty标签用法详解
Jun 30 PHP
PHP自定session保存路径及删除、注销与写入的方法
Nov 18 PHP
PHP中error_log()函数的使用方法
Jan 20 PHP
54个提高PHP程序运行效率的方法
Jul 19 PHP
redis查看连接数及php模拟并发创建redis连接的方法
Dec 15 PHP
Redis在Laravel项目中的应用实例详解
Aug 11 PHP
thinkPHP框架整合tcpdf插件操作示例
Aug 07 PHP
vmware linux系统安装最新的php7图解
Apr 14 PHP
PHP面向对象类型约束用法分析
Jun 12 PHP
PHP基于array_unique实现二维数组去重
Jul 14 PHP
php 文件上传类代码
Aug 06 #PHP
php代码运行时间查看类代码分享
Aug 06 #PHP
discuz程序的PHP加密函数原理分析
Aug 05 #PHP
PHP源码之explode使用说明
Aug 05 #PHP
PHP在获取指定目录下的目录,在获取的目录下面再创建文件,多平台
Aug 03 #PHP
php中获取远程客户端的真实ip地址的方法
Aug 03 #PHP
用PHP实现的四则运算表达式计算实现代码
Aug 02 #PHP
You might like
超神学院:鹤熙已踏入神圣领域,实力不比凯莎弱
2020/03/02 国漫
实现树状结构的两种方法
2006/10/09 PHP
用PHP实现Ftp用户的在线管理
2012/02/16 PHP
WordPress迁移时一些常见问题的解决方法整理
2015/11/24 PHP
Laravel框架实现多个视图共享相同数据的方法详解
2019/07/09 PHP
JavaScript CSS修改学习第五章 给“上传”添加样式
2010/02/19 Javascript
js FLASH幻灯片字符串中有连接符&的处理方法
2012/03/01 Javascript
购物车选中得到价格实现示例
2014/01/26 Javascript
JS实现鼠标单击与双击事件共存
2014/03/08 Javascript
javascript的事件触发器介绍的实现
2014/06/05 Javascript
JavaScript 实现打印,打印预览,打印设置
2014/12/30 Javascript
JS使用onerror捕获异常示例
2016/08/03 Javascript
bootstrap模态框实现拖拽效果
2016/12/14 Javascript
微信小程序 页面跳转如何实现传值
2017/04/05 Javascript
vue基于Vue2.0和高德地图的地图组件实例
2017/04/28 Javascript
JavaScript防止全局变量污染的方法总结
2018/08/02 Javascript
Vue 菜单栏点击切换单个class(高亮)的方法
2018/08/22 Javascript
15个顶级开源JavaScript框架和库
2018/10/10 Javascript
jquery.pager.js实现分页效果
2019/07/29 jQuery
JS hasOwnProperty()方法检测一个属性是否是对象的自有属性的方法
2021/01/29 Javascript
Python类方法__init__和__del__构造、析构过程分析
2015/03/06 Python
Python 装饰器使用详解
2017/07/29 Python
解决pycharm无法调用pip安装的包问题
2018/05/18 Python
Python中使用双下划线防止类属性被覆盖问题
2019/06/27 Python
Django 限制访问频率的思路详解
2019/12/24 Python
python实现按键精灵找色点击功能教程,使用pywin32和Pillow库
2020/06/04 Python
Python利用socket模块开发简单的端口扫描工具的实现
2021/01/27 Python
pandas按条件筛选数据的实现
2021/02/20 Python
Canvas绘制浮动球效果的示例
2017/12/29 HTML / CSS
大专学生推荐信范文
2013/11/19 职场文书
工程部经理岗位职责
2013/12/08 职场文书
五四青年节演讲稿
2014/05/26 职场文书
幼儿园托班开学寄语(2016春季)
2015/12/03 职场文书
2019年第四季度财务部门工作计划
2019/11/02 职场文书
CI Games宣布《堕落之王2》使用虚幻引擎5制作 预计将于2023年正式发售
2022/04/11 其他游戏
CSS link与@import的区别和用法解析
2023/05/07 HTML / CSS