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对象类型判断
Aug 27 PHP
PHP扩展编写点滴 技巧收集
Mar 09 PHP
php连接数据库代码应用分析
May 29 PHP
PHP utf-8编码问题,utf8编码,数据库乱码,页面显示输出乱码
Apr 08 PHP
PHP实现邮件群发的源码
Jun 18 PHP
PHP获取表单所有复选框的值的方法
Aug 28 PHP
php中字符串和正则表达式详解
Oct 23 PHP
ThinkPHP实现带验证码的文件上传功能实例
Nov 01 PHP
php中get_meta_tags()、CURL与user-agent用法分析
Dec 16 PHP
ThinkPHP模型详解
Jul 27 PHP
利用PHP自动生成印有用户信息的名片
Aug 01 PHP
PHP模糊查询的实现方法(推荐)
Sep 06 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
全国FM电台频率大全 - 19 广东省
2020/03/11 无线电
ThinkPHP之foreach标签使用概述
2014/06/30 PHP
ThinkPHP中Session用法详解
2014/11/29 PHP
php实现的日历程序
2015/06/18 PHP
PHP并发查询MySQL的实例代码
2017/08/09 PHP
jQuery MD5加密实现代码
2010/03/15 Javascript
解决jquery1.9不支持browser对象的问题
2013/11/13 Javascript
jQuery的live()方法对hover事件的处理示例
2014/02/27 Javascript
extjs 时间范围选择自动判断的实现代码
2014/06/24 Javascript
JS动态修改图片的URL(src)的方法
2015/04/01 Javascript
JavaScript中的Repaint和Reflow用法详解
2015/07/27 Javascript
如何用jQuery实现ASP.NET GridView折叠伸展效果
2015/09/26 Javascript
js中Number数字数值运算后值不对的解决方法
2017/02/28 Javascript
Vuex和前端缓存的整合策略详解
2017/05/09 Javascript
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解决方法
2017/06/17 Javascript
web前端vue filter 过滤器
2018/01/12 Javascript
详解webpack-dev-server使用http-proxy解决跨域问题
2018/01/13 Javascript
js字符串倒序的实例代码
2018/11/30 Javascript
[04:02]2014DOTA2国际邀请赛 BBC每日综述中国战队将再度登顶
2014/07/21 DOTA
[01:02:18]VGJ.S vs infamous Supermajor 败者组 BO3 第一场 6.4
2018/06/05 DOTA
Python3写入文件常用方法实例分析
2015/05/22 Python
Python常见格式化字符串方法小结【百分号与format方法】
2016/09/18 Python
如何使用python爬虫爬取要登陆的网站
2019/07/12 Python
Python Django 简单分页的实现代码解析
2019/08/21 Python
Python面向对象之私有属性和私有方法应用案例分析
2019/12/31 Python
Rodd & Gunn澳大利亚官网:新西兰男装品牌
2018/09/25 全球购物
牦牛毛户外探险服装:Kora
2019/02/08 全球购物
施华洛世奇波兰官网:SWAROVSKI波兰
2019/06/18 全球购物
超市实习总结自我鉴定
2013/09/19 职场文书
高中毕业生生活的自我评价
2013/12/08 职场文书
宿舍标语大全
2014/06/19 职场文书
2014年民主评议党员个人总结
2014/09/24 职场文书
老兵退伍标语
2014/10/07 职场文书
政风行风评议心得体会
2014/10/21 职场文书
捐资助学感谢信
2015/01/21 职场文书
婚庆公司开业主持词
2015/06/30 职场文书