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 相关文章推荐
discuz7 phpMysql操作类
Jun 21 PHP
Cakephp 执行主要流程
Mar 24 PHP
php上传文件的增强函数
Jul 21 PHP
PHP错误Allowed memory size of 67108864 bytes exhausted的3种解决办法
Jul 28 PHP
thinkphp3.2.2前后台公用类架构问题分析
Nov 25 PHP
php图片添加文字水印实现代码
Mar 15 PHP
PHP简单实现生成txt文件到指定目录的方法
Apr 25 PHP
Centos 6.5下PHP 5.3安装ffmpeg扩展的步骤详解
Mar 02 PHP
PHP 二维关联数组根据其中一个字段排序(推荐)
Apr 04 PHP
PHP手机号中间四位用星号*代替显示的实例
Jun 02 PHP
php图片裁剪函数
Oct 31 PHP
laravel实现简单用户权限的示例代码
May 28 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防止跨域提交表单
2013/11/01 PHP
PHP内核探索:变量概述
2014/01/30 PHP
php使用GD创建保持宽高比缩略图的方法
2015/04/17 PHP
PHP简单实现HTTP和HTTPS跨域共享session解决办法
2015/05/27 PHP
php使用QueryList轻松采集js动态渲染页面方法
2018/09/11 PHP
Cookie 注入是怎样产生的
2009/04/08 Javascript
JavaScript mapreduce工作原理简析
2012/11/25 Javascript
javascript获取ckeditor编辑器的值(实现代码)
2013/11/18 Javascript
javascript编写贪吃蛇游戏
2015/07/07 Javascript
jQuery的 $.ajax防止重复提交的两种方法(推荐)
2016/10/14 Javascript
jQuery实现CheckBox全选、全不选功能
2017/01/11 Javascript
Vue.js实现分页查询功能
2020/11/15 Javascript
详解vue axios用post提交的数据格式
2018/08/07 Javascript
vue地址栏直接输入路由无效问题的解决
2018/11/15 Javascript
微信小程序如何修改本地缓存key中单个数据的详解
2019/04/26 Javascript
7个好用的JavaScript技巧分享(译)
2019/05/07 Javascript
Node.js中console.log()输出彩色字体的方法示例
2019/12/01 Javascript
vuex管理状态仓库使用详解
2020/07/29 Javascript
JS中队列和双端队列实现及应用详解
2020/09/29 Javascript
基于vue与element实现创建试卷相关功能(实例代码)
2020/12/07 Vue.js
Vue中ref和$refs的介绍以及使用方法示例
2021/01/11 Vue.js
node.js 基于 STMP 协议和 EWS 协议发送邮件
2021/02/14 Javascript
[01:18]一目了然!DOTA2DotA快捷操作对比第一弹
2014/07/01 DOTA
python获取文件版本信息、公司名和产品名的方法
2014/10/05 Python
Python读取英文文件并记录每个单词出现次数后降序输出示例
2018/06/28 Python
python版opencv摄像头人脸实时检测方法
2018/08/03 Python
python encrypt 实现AES加密的实例详解
2020/02/20 Python
Django admin 实现search_fields精确查询实例
2020/03/30 Python
节省高达65%的城市景点费用:Go City
2019/07/06 全球购物
趣天网日本站:Qoo10 JP
2019/09/18 全球购物
J2EE包括哪些技术
2016/11/25 面试题
2014道德模范事迹材料
2014/02/16 职场文书
Vue全家桶入门基础教程
2021/05/14 Vue.js
python 如何做一个识别率百分百的OCR
2021/05/29 Python
浅谈MySql整型索引和字符串索引失效或隐式转换问题
2021/11/20 MySQL
nginx容器方式反向代理实战
2022/04/18 Servers