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 getimagesize 上传图片的长度和宽度检测代码
May 15 PHP
php imagecreatetruecolor 创建高清和透明图片代码小结
May 15 PHP
超级好用的一个php上传图片类(随机名,缩略图,加水印)
Jun 30 PHP
Look And Say 序列php实现代码
May 22 PHP
url decode problem 解决方法
Dec 26 PHP
浅析Mysql 数据回滚错误的解决方法
Aug 05 PHP
php连接oracle数据库及查询数据的方法
Dec 29 PHP
php递归删除目录与文件的方法
Jan 30 PHP
注意!PHP 7中不要做的10件事
Sep 18 PHP
php UNIX时间戳用法详解
Feb 16 PHP
Laravel访问出错提示:`Warning: require(/vendor/autoload.php): failed to open stream: No such file or di解决方法
Apr 02 PHP
PHP实现获取url地址中顶级域名的方法示例
Jun 05 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函数)
2006/10/09 PHP
基于Snoopy的PHP近似完美获取网站编码的代码
2011/10/23 PHP
PHP连接sftp并下载文件的方法教程
2018/08/26 PHP
php面向对象程序设计入门教程
2019/06/22 PHP
学习YUI.Ext 第六天--关于树TreePanel(Part 2异步获取节点)
2007/03/10 Javascript
jQuery + Flex 通过拖拽方式动态改变图片的代码
2011/08/03 Javascript
Jquery 选中表格一列并对表格排序实现原理
2012/12/15 Javascript
超简单JS二级、多级联动的简单实例
2014/02/18 Javascript
js实现按一下删除键删除整个单词附demo
2014/09/05 Javascript
分析了一下JQuery中的extend方法实现原理
2015/02/27 Javascript
详解JavaScript的另类写法
2016/04/11 Javascript
BootStrap入门教程(三)之响应式原理
2016/09/19 Javascript
通过bootstrap全面学习less
2016/11/09 Javascript
详解angularJs中自定义directive的数据交互
2017/01/13 Javascript
JS中mouseup事件丢失的原因与解决办法
2017/06/14 Javascript
karma+webpack搭建vue单元测试环境的方法示例
2018/05/24 Javascript
JavaScript 作用域scope简单汇总
2019/10/23 Javascript
Python字符编码判断方法分析
2016/07/01 Python
python中pandas.DataFrame的简单操作方法(创建、索引、增添与删除)
2017/03/12 Python
python字典DICT类型合并详解
2017/08/17 Python
Python PyQt5标准对话框用法示例
2017/08/23 Python
Numpy之文件存取的示例代码
2018/08/03 Python
Django ModelForm操作及验证方式
2020/03/30 Python
python实现学生管理系统开发
2020/07/24 Python
python中Array和DataFrame相互转换的实例讲解
2021/02/03 Python
Sneaker Studio波兰:购买运动鞋
2018/04/28 全球购物
Linux常见面试题
2016/10/04 面试题
临床医学专业毕业生的自我评价
2013/10/17 职场文书
电子信息工程专业推荐信
2014/02/14 职场文书
高校师德师风自我剖析材料
2014/09/29 职场文书
2014年后勤管理工作总结
2014/12/01 职场文书
2015年上半年信访工作总结
2015/03/30 职场文书
刑事撤诉申请书
2015/05/18 职场文书
中学音乐课教学反思
2016/02/18 职场文书
如何利用golang运用mysql数据库
2022/03/13 Golang
Dashboard管理Kubernetes集群与API访问配置
2022/04/01 Servers