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 相关文章推荐
JAVA/JSP学习系列之四
Oct 09 PHP
php 用checkbox一次性删除多条记录的方法
Feb 23 PHP
php Smarty模板生成html文档的方法
Apr 12 PHP
PHP网页游戏学习之Xnova(ogame)源码解读(十五)
Jun 30 PHP
php打印输出棋盘的实现方法
Dec 23 PHP
php表单提交与$_POST实例分析
Jan 26 PHP
php实现的debug log日志操作类实例
Jul 12 PHP
PHP简单实现二维数组的矩阵转置操作示例
Nov 24 PHP
PHP压缩图片功能的介绍
Mar 21 PHP
不常用但很实用的PHP预定义变量分析
Jun 25 PHP
php 策略模式原理与应用深入理解
Sep 25 PHP
PHP7移除的扩展和SAPI
Mar 09 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
PHP学习之正则表达式
2011/04/17 PHP
PHP中3种生成XML文件方法的速度效率比较
2012/10/06 PHP
使用php测试硬盘写入速度示例
2014/01/27 PHP
PHP基于session.upload_progress 实现文件上传进度显示功能详解
2019/08/09 PHP
JS宝典学习笔记(下)
2007/01/10 Javascript
在JavaScript中使用inline函数的问题
2007/03/08 Javascript
JQuery扩展插件Validate—6 radio、checkbox、select的验证
2011/09/05 Javascript
javascript实现时间格式输出FormatDate函数
2015/01/13 Javascript
DOM基础教程之使用DOM设置文本框
2015/01/20 Javascript
JavaScript事件委托用法分析
2015/01/24 Javascript
js实现同一个页面多个渐变效果的方法
2015/04/10 Javascript
JS实现来回出现文字的状态栏特效代码
2015/10/31 Javascript
实例讲解jquery中mouseleave和mouseout的区别
2016/02/17 Javascript
create-react-app构建项目慢的解决方法
2018/03/14 Javascript
解决vue 按钮多次点击重复提交数据问题
2018/05/10 Javascript
SVG实现时钟效果
2018/07/17 Javascript
详解webpack2异步加载套路
2018/09/14 Javascript
layer弹出层显示在top顶层的方法
2019/09/11 Javascript
解决VantUI popup 弹窗不弹出或无蒙层的问题
2020/11/03 Javascript
Python实现自定义顺序、排列写入数据到Excel的方法
2018/04/23 Python
Python wxPython库消息对话框MessageDialog用法示例
2018/09/03 Python
python将视频转换为全字符视频
2019/04/26 Python
Python如何使用函数做字典的值
2019/11/30 Python
python中time包实例详解
2021/02/02 Python
Python如何telnet到网络设备
2021/02/18 Python
哄娃神器4moms商店:美国婴童用品品牌
2019/03/07 全球购物
JAVA中的关键字有什么特点
2014/03/07 面试题
怎样客观的做好自我评价
2013/12/28 职场文书
授权委托书格式模板
2014/04/03 职场文书
三关爱志愿服务活动方案
2014/08/17 职场文书
四风问题查摆材料
2014/08/25 职场文书
社区创先争优承诺书
2014/08/30 职场文书
2014年科室工作总结范文
2014/12/19 职场文书
招标保密承诺书
2015/01/20 职场文书
医德医风学习心得体会
2016/01/25 职场文书
Android开发手册Chip监听及ChipGroup监听
2022/06/10 Java/Android