分享PHP header函数使用教程


Posted in PHP onSeptember 05, 2013
<?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 会话(session 时间设定)使用入门代码
Jun 05 PHP
php下检测字符串是否是utf8编码的代码
Jun 28 PHP
ueditor 1.2.6 使用方法说明
Jul 24 PHP
PHP中加密解密函数与DES加密解密实例
Oct 17 PHP
PHP解析目录路径的3个函数总结
Nov 18 PHP
php+mysql实现无限分类实例详解
Jan 15 PHP
PHP自定义函数获取汉字首字母的方法
Dec 01 PHP
thinkPHP显示不出验证码的原因与解决方法分析
May 20 PHP
PHP大文件分割上传 PHP分片上传
Aug 28 PHP
浅析PHP echo 和 print 语句
Jun 30 PHP
php解析非标准json、非规范json的方式实例
Dec 10 PHP
PHP实现chrome表单请求数据转换为接口使用的json数据
Mar 04 PHP
php增删改查示例自己写的demo
Sep 04 #PHP
php使用异或实现的加密解密实例
Sep 04 #PHP
PHP中数组定义的几种方法
Sep 01 #PHP
对淘宝URL中ID提取的PHP代码
Sep 01 #PHP
怎么在Windows系统中搭建php环境
Aug 31 #PHP
深入解析php中的foreach函数
Aug 31 #PHP
如何使用php输出时间格式
Aug 31 #PHP
You might like
数组与类使用PHP的可变变量名需要的注意的问题
2013/06/20 PHP
php实现Session存储到Redis
2015/11/11 PHP
PHP 中魔术常量的实例详解
2017/10/26 PHP
统计PHP目录中的文件数方法
2019/03/05 PHP
ymPrompt的doHandler方法来实现获取子窗口返回值的方法
2010/06/25 Javascript
jquery实现的让超出显示范围外的导航自动固定屏幕最顶上
2011/09/22 Javascript
IFrame跨域高度自适应实现代码
2012/08/16 Javascript
相册展示PhotoSwipe.js插件实现
2016/08/25 Javascript
JS中微信小程序自定义底部弹出框
2016/12/22 Javascript
详解Sea.js中Module.exports和exports的区别
2017/02/12 Javascript
从零开始学习Node.js系列教程之SQLite3和MongoDB用法分析
2017/04/13 Javascript
JavaScript 通过Ajax 动态加载CheckBox复选框
2017/08/31 Javascript
结合mint-ui移动端下拉加载实践方法总结
2017/11/08 Javascript
微信小程序搜索功能(附:小程序前端+PHP后端)
2019/02/28 Javascript
详解Vue的mixin策略
2020/11/19 Vue.js
Android应用开发中Action bar编写的入门教程
2016/02/26 Python
python学生信息管理系统(初级版)
2018/10/17 Python
对Python中一维向量和一维向量转置相乘的方法详解
2019/08/26 Python
Python3 io文本及原始流I/O工具用法详解
2020/03/23 Python
django rest framework serializers序列化实例
2020/05/13 Python
简单了解python关键字global nonlocal区别
2020/09/21 Python
python 读取串口数据的示例
2020/11/09 Python
Html5页面二次分享的实现
2018/07/30 HTML / CSS
娇韵诗法国官网:Clarins法国
2019/01/29 全球购物
你对IPv6了解程度
2016/02/09 面试题
Linux Interview Questions For software testers
2012/06/02 面试题
大学生毕业自我鉴定范文
2013/09/19 职场文书
八年级美术教学反思
2014/02/02 职场文书
2015医院个人工作总结范文
2015/05/21 职场文书
2015年外贸业务员工作总结范文
2015/05/23 职场文书
毕业生政审意见范文
2015/06/04 职场文书
安全知识竞赛主持词
2015/06/30 职场文书
葬礼主持词
2015/07/02 职场文书
运动会班级口号霸气押韵
2015/12/24 职场文书
Python中tkinter的用户登录管理的实现
2021/04/22 Python
GoFrame框架数据校验之校验结果Error接口对象
2022/06/21 Golang