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中for循环语句的几种变型
Nov 26 PHP
PHP 根据IP地址控制访问的代码
Apr 22 PHP
php var_export与var_dump 输出的不同
Aug 09 PHP
php中memcache 基本操作实例
May 17 PHP
PHP中JSON的应用技巧
Oct 10 PHP
php验证手机号码
Nov 11 PHP
Smarty变量用法详解
May 11 PHP
PHP判断用户是否已经登录(跳转到不同页面或者执行不同动作)
Sep 22 PHP
php实现跨域提交form表单的方法【2种方法】
Oct 17 PHP
使用PHPStorm+XDebug搭建单步调试环境
Nov 19 PHP
PHP使用PDO、mysqli扩展实现与数据库交互操作详解
Jul 20 PHP
使用git迁移Laravel项目至新开发环境的步骤详解
Apr 06 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
header导出Excel应用示例
2014/01/24 PHP
php对象和数组相互转换的方法
2015/05/12 PHP
php支持断点续传、分块下载的类
2016/05/02 PHP
PHP输出XML格式数据的方法总结
2017/02/08 PHP
php实现的双色球算法示例
2017/06/20 PHP
PHP数据分析引擎计算余弦相似度算法示例
2017/08/08 PHP
原生php实现excel文件读写的方法分析
2018/04/25 PHP
Javascript的闭包
2009/12/31 Javascript
js 中 document.createEvent的用法
2010/08/29 Javascript
JQuery中绑定事件(bind())和移除事件(unbind())
2015/02/27 Javascript
谈谈JavaScript中function多重理解
2015/08/28 Javascript
微信小程序开发背景图显示功能
2018/08/08 Javascript
详解基于iview-ui的导航栏路径(面包屑)配置
2019/02/22 Javascript
小程序实现按下录音松开识别语音
2019/11/22 Javascript
vue vant Area组件使用详解
2019/12/09 Javascript
JS的时间格式化和时间戳转换函数示例详解
2020/07/27 Javascript
[02:27]2018DOTA2亚洲邀请赛赛前采访-OpTic
2018/04/03 DOTA
使用Python从有道词典网页获取单词翻译
2016/07/03 Python
python 生成器生成杨辉三角的方法(必看)
2017/04/10 Python
Python 通过pip安装Django详细介绍
2017/04/28 Python
Python实现生成随机日期字符串的方法示例
2017/12/25 Python
python3解析库pyquery的深入讲解
2018/06/26 Python
Python调用graphviz绘制结构化图形网络示例
2019/11/22 Python
tensorboard实现同时显示训练曲线和测试曲线
2020/01/21 Python
python BeautifulSoup库的安装与使用
2020/12/17 Python
python Timer 类使用介绍
2020/12/28 Python
日本民宿预约平台:STAY JAPAN
2017/07/01 全球购物
Aeropostale官网:美国著名校园品牌及青少年服饰品牌
2019/03/21 全球购物
英国豪华家具和经典家居饰品购物网站:OKA
2020/06/05 全球购物
客服端调用EJB对象的几个基本步骤
2012/01/15 面试题
车间班组长岗位职责
2013/11/13 职场文书
食品安全工作实施方案
2014/03/26 职场文书
金融专业求职信
2014/08/05 职场文书
获奖感言怎么写
2015/07/31 职场文书
手把手教你制定暑期学习计划,让你度过充实的暑假
2019/08/22 职场文书
Django使用channels + websocket打造在线聊天室
2021/05/20 Python