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代码(星期六,星期日总和)
Nov 12 PHP
php checkbox复选框值的获取与checkbox默认值输出方法
May 15 PHP
深入php define()函数以及defined()函数的用法详解
Jun 05 PHP
浅谈php正则表达式中的非贪婪模式匹配的使用
Nov 25 PHP
php实现的通用图片处理类
Mar 24 PHP
PHP入门教程之数学运算技巧总结
Sep 11 PHP
php 修改上传文件大小限制实例详解
Oct 23 PHP
php+ajax无刷新上传图片的实现方法
Dec 06 PHP
PHP面向对象学习之parent::关键字
Jan 18 PHP
PHP函数积累总结
Mar 19 PHP
PHP swoole和redis异步任务实现方法分析
Aug 12 PHP
Thinkphp 框架扩展之应用模式实现方法分析
Apr 27 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
smarty半小时快速上手入门教程
2014/10/27 PHP
PHP中字符与字节的区别及字符串与字节转换示例
2016/10/15 PHP
简单三步,搞掂内存泄漏
2007/03/10 Javascript
jQuery 学习第五课 Ajax 使用说明
2010/05/17 Javascript
Javascript学习笔记-详解in运算符
2011/09/13 Javascript
阻止子元素继承父元素事件具体思路及实现
2013/05/02 Javascript
jquery弹出关闭遮罩层实例
2013/08/06 Javascript
兼容主流浏览器的iframe自适应高度js脚本
2014/01/10 Javascript
jQuery中each()方法用法实例
2014/12/27 Javascript
JS实现的竖向折叠菜单代码
2015/10/21 Javascript
js鼠标点击图片切换效果实现代码
2015/11/19 Javascript
JavaScript判断DIV内容是否为空的方法
2016/01/29 Javascript
jQuery插件FusionCharts绘制2D双折线图效果示例【附demo源码】
2017/04/14 jQuery
微信小程序picker组件下拉框选择input输入框的实例
2017/09/20 Javascript
微信小程序js文件改变参数并在视图上及时更新【推荐】
2018/06/11 Javascript
vue定义全局变量和全局方法的方法示例
2018/08/01 Javascript
深度了解vue.js中hooks的相关知识
2019/06/14 Javascript
windows实现npm和cnpm安装步骤
2019/10/24 Javascript
浅谈vue异步数据影响页面渲染
2019/10/29 Javascript
Python批量创建迅雷任务及创建多个文件
2016/02/13 Python
Python常用时间操作总结【取得当前时间、时间函数、应用等】
2017/05/11 Python
python Django 创建应用过程图示详解
2019/07/29 Python
Python Switch Case三种实现方法代码实例
2020/06/18 Python
PyTorch实现重写/改写Dataset并载入Dataloader
2020/07/14 Python
python selenium xpath定位操作
2020/09/01 Python
HTML5视频播放插件 video.js介绍
2018/09/29 HTML / CSS
对于没有初始化的变量的初始值可以作怎样的假定
2014/10/12 面试题
写好求职应聘自荐信的三部曲
2013/09/21 职场文书
大学同学聚会邀请函
2014/01/29 职场文书
2014年重阳节老干部座谈会局领导发言稿
2014/09/25 职场文书
门市房租房协议书
2014/12/04 职场文书
五好文明家庭事迹材料
2014/12/20 职场文书
社会实践活动总结
2015/02/05 职场文书
表扬信格式模板
2015/05/05 职场文书
优秀乡村医生事迹材料(2016精选版)
2016/02/29 职场文书
Python 类,对象,数据分类,函数参数传递详解
2021/09/25 Python