分享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函数
Jan 11 PHP
php实现查看邮件是否已被阅读的方法
Dec 03 PHP
PHP static局部静态变量和全局静态变量总结
Mar 02 PHP
php的webservice的wsdl的XML无法显示问题的解决方法
Mar 11 PHP
php中foreach结合curl实现多线程的方法分析
Sep 22 PHP
php is_writable判断文件是否可写实例代码
Oct 13 PHP
ThinkPHP Where 条件中常用表达式示例(详解)
Mar 31 PHP
PHP实现防止表单重复提交功能【基于token验证】
May 24 PHP
PHP实现微信提现功能
Sep 30 PHP
PHP面向对象类型约束用法分析
Jun 12 PHP
Laravel关系模型指定条件查询方法
Oct 10 PHP
php 防护xss,PHP的防御XSS注入的终极解决方案
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
PHP 5.0对象模型深度探索之绑定
2006/09/05 PHP
MVC模式的PHP实现
2006/10/09 PHP
php中通过curl smtp发送邮件
2012/06/05 PHP
php利用腾讯ip分享计划获取地理位置示例分享
2014/01/20 PHP
PHP中数组的分组排序实例
2014/06/01 PHP
Laravel框架数据库CURD操作、连贯操作总结
2014/09/03 PHP
PHP结合Jquery和ajax实现瀑布流特效
2016/01/07 PHP
php实现基于openssl的加密解密方法
2016/09/30 PHP
php中青蛙跳台阶的问题解决方法
2018/10/14 PHP
Laravel创建数据库表结构的例子
2019/10/09 PHP
javascript之dhDataGrid Ver2.0.0代码
2007/07/01 Javascript
JqGrid web打印实现代码
2011/05/31 Javascript
js事件委托和事件代理案例分享
2017/07/25 Javascript
vue点击input弹出带搜索键盘并监听该元素的方法
2018/08/25 Javascript
vue中nextTick用法实例
2019/09/11 Javascript
vue制作抓娃娃机的示例代码
2020/04/17 Javascript
javascript设计模式 ? 命令模式原理与用法实例分析
2020/04/20 Javascript
js实现简单贪吃蛇游戏
2020/05/15 Javascript
VueCli生产环境打包部署跨域失败的解决
2020/11/13 Javascript
[04:48]DOTA2亚洲邀请赛林书豪为VGJ加油
2017/04/01 DOTA
如何在Python函数执行前后增加额外的行为
2016/10/20 Python
python使用Apriori算法进行关联性解析
2017/12/21 Python
Python实现的根据文件名查找数据文件功能示例
2018/05/02 Python
关于Python中的向量相加和numpy中的向量相加效率对比
2019/08/26 Python
python三引号如何输入
2020/07/06 Python
python中watchdog文件监控与检测上传功能
2020/10/30 Python
采用冷却技术的超自然舒适度:GhostBed床垫
2018/09/18 全球购物
do you have any Best Practice for testing
2016/06/04 面试题
拉丁舞学习者的自我评价
2013/10/27 职场文书
社会实践评语
2014/04/28 职场文书
洗手间标语
2014/06/23 职场文书
公证委托书标准格式
2014/09/11 职场文书
2015年财务工作总结范文
2015/03/31 职场文书
2016年119消防宣传日活动总结
2016/04/05 职场文书
2019年暑期法院实习报告
2019/12/18 职场文书
PyMongo 查询数据的实现
2021/06/28 Python