分享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 mysql索引问题
Jun 07 PHP
php array_push()数组函数:将一个或多个单元压入数组的末尾(入栈)
Jul 12 PHP
五款PHP代码重构工具推荐
Oct 14 PHP
PHP实现将视频转成MP4并获取视频预览图的方法
Mar 12 PHP
分享3个php获取日历的函数
Sep 25 PHP
PHP中overload与override的区别
Feb 13 PHP
Laravel 中使用 Vue.js 实现基于 Ajax 的表单提交错误验证操作
Jun 30 PHP
利用PHP访问MySql数据库的逻辑操作以及增删改查的实例讲解
Aug 30 PHP
一次因composer错误使用引发的问题与解决
Mar 06 PHP
PHP使用反向Ajax技术实现在线客服系统详解
Jul 01 PHP
Yii Framework框架使用PHPExcel组件的方法示例
Jul 24 PHP
php中try catch捕获异常实例详解
Aug 06 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
星际争霸任务指南——人族
2020/03/04 星际争霸
用PHP控制用户的浏览器--ob*函数的使用说明
2007/03/16 PHP
很好用的PHP数据库类
2009/05/27 PHP
php 定界符格式引起的错误
2011/05/24 PHP
通过php快速统计某个数据库中每张表的数据量
2012/09/04 PHP
PHP遍历数组的三种方法及效率对比分析
2015/02/12 PHP
Yii学习总结之数据访问对象 (DAO)
2015/02/22 PHP
PHP 验证登陆类分享
2015/03/13 PHP
实现WordPress主题侧边栏切换功能的PHP脚本详解
2015/12/14 PHP
php获取一定范围内取N个不重复的随机数
2016/05/28 PHP
PHP MYSQL简易交互式站点开发
2016/12/27 PHP
JS、DOM和JQuery之间的关系示例分析
2014/04/09 Javascript
javascript在网页中实现读取剪贴板粘贴截图功能
2014/06/07 Javascript
IONIC自定义subheader的最佳解决方案
2016/09/22 Javascript
JavaScript 控制字体大小设置的方法
2016/11/23 Javascript
Javascript前端经典的面试题及答案
2017/03/14 Javascript
web前端页面生成exe可执行文件的方法
2018/02/08 Javascript
详解React-Router中Url参数改变页面不刷新的解决办法
2018/05/08 Javascript
Vue通过WebSocket建立长连接的实现代码
2019/11/05 Javascript
vue element table中自定义一些input的验证操作
2020/07/18 Javascript
[01:45]典藏宝瓶2+祈求者身心——这就是DOTA2TI9总奖金突破3000万美元的秘密
2019/07/21 DOTA
python 判断自定义对象类型
2009/03/21 Python
Python迭代器和生成器介绍
2015/03/06 Python
Python实现更改图片尺寸大小的方法(基于Pillow包)
2016/09/19 Python
python利用urllib实现爬取京东网站商品图片的爬虫实例
2017/08/24 Python
python获取代码运行时间的实例代码
2018/06/11 Python
春秋航空官方网站:Spring Airlines
2017/09/27 全球购物
欧尚俄罗斯网上超市:Auchan俄罗斯
2018/05/03 全球购物
电气工程和自动化自荐信范文
2013/12/25 职场文书
教师绩效考核方案
2014/01/21 职场文书
领导调研接待方案
2014/02/27 职场文书
八一建军节演讲稿
2014/09/10 职场文书
网络舆情信息简报
2015/07/21 职场文书
2016先进集体事迹材料范文
2016/02/25 职场文书
浙江省杭州市平均工资标准是多少?
2019/07/09 职场文书
spring项目中切面及AOP的使用方法
2021/06/26 Java/Android