分享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中的时间处理
Oct 09 PHP
计算2000年01月01日起到指定日的天数
Oct 09 PHP
PHP获得用户使用的代理服务器ip即真实ip
Dec 31 PHP
phpmyadmin config.inc.php配置示例
Aug 27 PHP
destoon之一键登录设置
Jun 21 PHP
php中单个数据库字段多列显示(单字段分页、横向输出)
Jul 28 PHP
smarty模板引擎之分配数据类型
Mar 30 PHP
php实现简单爬虫的开发
Mar 28 PHP
ThinkPHP中order()使用方法详解
Apr 19 PHP
php实现批量删除挂马文件及批量替换页面内容完整实例
Jul 08 PHP
php数值转换时间及时间转换数值用法示例
May 18 PHP
php 获取音视频时长,PHP 利用getid3 获取音频文件时长等数据
Apr 01 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
玩家交还《星际争霸》原始码光盘 暴雪报以厚礼
2017/05/05 星际争霸
锁定年轻人的双倍活力 星巴克推出星倍醇即饮浓咖啡
2021/03/03 咖啡文化
php和mysql中uft-8中文编码乱码的几种解决办法
2012/04/19 PHP
解析php扩展php_curl.dll不加载的解决方法
2013/06/26 PHP
跟我学Node.js(四)---Node.js的模块载入方式与机制
2014/06/04 Javascript
详解javascript遍历方式
2015/11/11 Javascript
JS实现弹出居中的模式窗口示例
2016/06/20 Javascript
js实现千分符和保留几位小数的简单实例
2016/08/01 Javascript
jQuery中clone()函数实现表单中增加和减少输入项
2017/05/13 jQuery
Bootstrap Multiselect 常用组件实现代码
2017/07/09 Javascript
jQuery实现导航栏头部菜单项点击后变换颜色的方法
2017/07/19 jQuery
Extjs 中的 Treepanel 实现菜单级联选中效果及实例代码
2017/08/22 Javascript
ionic2中使用自动生成器的方法
2018/03/04 Javascript
浅谈Vue 数据响应式原理
2018/05/07 Javascript
JavaScript中引用vs复制示例详析
2018/12/06 Javascript
JS实现的A*寻路算法详解
2018/12/14 Javascript
JS添加或删除HTML dom元素的方法实例分析
2019/03/05 Javascript
使用 Vue cli 3.0 构建自定义组件库的方法
2019/04/30 Javascript
Vue封装的组件全局注册并引用
2019/07/24 Javascript
Element Backtop回到顶部的具体使用
2020/07/27 Javascript
详解python3百度指数抓取实例
2016/12/12 Python
python随机取list中的元素方法
2018/04/08 Python
python 获取当天凌晨零点的时间戳方法
2018/05/22 Python
python opencv实现切变换 不裁减图片
2018/07/26 Python
python斐波那契数列的计算方法
2018/09/27 Python
Python with用法:自动关闭文件进程
2019/07/10 Python
python 控制Asterisk AMI接口外呼电话的例子
2019/08/08 Python
在TensorFlow中屏蔽warning的方式
2020/02/04 Python
什么是ESB?请介绍一下ESB?
2015/05/27 面试题
大学自我评价
2014/02/12 职场文书
硕士学位论文评语
2014/12/31 职场文书
同学聚会邀请函
2015/01/30 职场文书
世界地球日活动总结
2015/02/09 职场文书
教师“一帮一”结对子活动总结
2015/05/07 职场文书
《怀念母亲》教学反思
2016/02/19 职场文书
2019年大学生暑期社会实践调查报告模板
2019/11/07 职场文书