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 相关文章推荐
用Flash图形化数据(一)
Oct 09 PHP
让php处理图片变得简单 基于gb库的图片处理类附实例代码下载
May 17 PHP
Fatal error: session_start(): Failed to initialize storage module: files问题解决方法
May 04 PHP
ThinkPHP行为扩展Behavior应用实例详解
Jul 22 PHP
php中实现可以返回多个值的函数实例
Mar 21 PHP
PHP的时间戳与具体时间转化的简单实现
Jun 13 PHP
php多线程并发实现方法
Sep 30 PHP
php安全配置记录和常见错误梳理(总结)
Mar 28 PHP
利用PHP如何统计Nginx日志的User Agent数据
Mar 06 PHP
一次因composer错误使用引发的问题与解决
Mar 06 PHP
laravel返回统一格式错误码问题
Nov 04 PHP
Laravel5.1 框架Request请求操作常见用法实例分析
Jan 04 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
推荐几部必看的DC动画电影
2020/03/03 欧美动漫
isset和empty的区别
2007/01/15 PHP
PHP 接入微信扫码支付总结(总结篇)
2016/11/03 PHP
php对接java现实加签验签的实例
2016/11/25 PHP
jQuery 位置插件
2008/12/25 Javascript
关于flash遮盖div浮动层的解决方法
2010/07/17 Javascript
禁止选中文字兼容IE、Chrome、FF等
2013/09/04 Javascript
js中关于一个分号的崩溃示例
2013/11/11 Javascript
jQuery移除tr无效的解决方法(tr是动态添加)
2014/09/22 Javascript
JavaScript获得页面base标签中url的方法
2015/04/03 Javascript
在JavaScript中处理字符串之fontcolor()方法的使用
2015/06/08 Javascript
Backbone.js 0.9.2 源码注释中文翻译版
2015/06/25 Javascript
js操作数组函数实例小结
2015/12/10 Javascript
解析Node.js异常处理中domain模块的使用方法
2016/02/16 Javascript
bootstrap suggest下拉框使用详解
2017/04/10 Javascript
关于vue.js组件数据流的问题
2017/07/26 Javascript
javascript性能优化之分时函数的介绍
2018/03/28 Javascript
微信小程序实现复选框效果
2018/12/28 Javascript
layui弹出框Tab选项卡的示例代码
2019/09/04 Javascript
解决vue组件中click事件失效的问题
2019/11/09 Javascript
vue中对象数组去重的实现
2020/02/06 Javascript
Django中实现一个高性能计数器(Counter)实例
2014/07/09 Python
Python3中的真除和Floor除法用法分析
2016/03/16 Python
Python实现图片转字符画的示例
2017/08/22 Python
python奇偶行分开存储实现代码
2018/03/19 Python
python实现两个一维列表合并成一个二维列表
2019/12/02 Python
The North Face北面荷兰官网:美国著名户外品牌
2019/10/16 全球购物
医学生实习自我鉴定
2013/09/27 职场文书
投标人法定代表人授权委托书格式
2014/09/28 职场文书
上课玩手机的检讨书
2014/10/01 职场文书
农业生产宣传标语
2014/10/08 职场文书
2014年监理工作总结范文
2014/11/17 职场文书
《夜莺的歌声》教学反思
2016/02/22 职场文书
同学联谊会邀请函
2019/06/24 职场文书
2019年特色火锅店的创业计划书模板
2019/08/28 职场文书
css弧边选项卡的项目实践
2023/05/07 HTML / CSS