php header示例代码(推荐)


Posted in PHP onSeptember 08, 2010
<?php 
/*** Function: PHP header() examples (PHP) 
** Desc: Some examples on how to use the header() function of PHPYou find a detailed tutorial at expertsrt.com (English) or at ffm.junetz.de (German).These is also a good help about caching at web-caching.com. 
** Example: see below. <br/><br/><b>Tip:</b> You can use these sites to check your headers: <a href="http://web-sniffer.net/">web-sniffer.net</a>, <a href="http://www.delorie.com/web/headers.html">delorie.com</a> or <a href="http://www.forret.com/projects/analyze/">www.forret.com</a>. 
** Author: Jonas John 
*/ // 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 相关文章推荐
Zend引擎的发展 [15]
Oct 09 PHP
BBS(php &amp; mysql)完整版(二)
Oct 09 PHP
PHP中10个不常见却非常有用的函数
Mar 21 PHP
Windows 下的 PHP-PEAR 安装方法
Nov 20 PHP
phpmailer中文乱码问题的解决方法
Apr 22 PHP
JavaScript创建命名空间的5种写法
Jun 24 PHP
weiphp微信公众平台授权设置
Jan 04 PHP
Symfony2学习笔记之模板用法详解
Mar 17 PHP
PHP获取数据库表中的数据插入新的表再原删除数据方法
Oct 12 PHP
PHP实现基本留言板功能原理与步骤详解
Mar 26 PHP
Thinkphp 框架基础之源码获取、环境要求与目录结构分析
Apr 27 PHP
PHP哈希表实现算法原理解析
Dec 11 PHP
php下清空字符串中的HTML标签的代码
Sep 06 #PHP
在PHP中PDO解决中文乱码问题的一些补充
Sep 06 #PHP
检测png图片是否完整的php代码
Sep 06 #PHP
晋城吧对DiscuzX进行的前端优化要点
Sep 05 #PHP
用PHP将数据导入到Foxmail的实现代码
Sep 05 #PHP
提高PHP编程效率的53个要点(经验小结)
Sep 04 #PHP
队列在编程中的实际应用(php)
Sep 04 #PHP
You might like
常用的php对象类型判断
2008/08/27 PHP
php的ajax框架xajax入门与试用介绍
2010/12/19 PHP
保存到桌面、设为桌面且带图标的PHP代码
2013/11/19 PHP
php实现telnet功能示例
2014/04/08 PHP
php5.4以下版本json不支持不转义内容中文的解决方法
2015/01/13 PHP
PHP常用函数之格式化时间操作示例
2019/10/21 PHP
通过实例解析PHP数据类型转换方法
2020/07/11 PHP
HTTP状态代码以及定义(解释)
2007/02/02 Javascript
FLASH 广告之外的链接
2008/12/16 Javascript
jQuery 入门级学习笔记及源码
2010/01/22 Javascript
基于jQuery实现的水平和垂直居中的div窗口
2011/08/08 Javascript
妙用Jquery的val()方法
2012/06/27 Javascript
用Jquery重写windows.alert方法实现思路
2013/04/03 Javascript
js获取客户端外网ip的简单实例
2013/11/21 Javascript
extJS中常用的4种Ajax异步提交方式
2014/03/07 Javascript
jQuery 顶部导航跟随滚动条滚动固定浮动在顶部
2014/06/06 Javascript
JavaScript 面向对象与原型
2015/04/10 Javascript
基于JSON格式数据的简单jQuery幻灯片插件(jquery-slider)
2016/08/10 Javascript
canvas学习之API整理笔记(一)
2016/12/29 Javascript
Bootstrap输入框组件简单实现代码
2017/03/06 Javascript
javascript checkbox/radio onchange不能兼容ie8处理办法
2017/06/13 Javascript
vue 1.0 结合animate.css定义动画效果
2018/07/11 Javascript
vue如何安装使用Quill富文本编辑器
2018/09/21 Javascript
浅谈Node 异步IO和事件循环
2019/05/05 Javascript
js动态添加带圆圈序号列表的实例代码
2021/02/18 Javascript
[48:32]2018DOTA2亚洲邀请赛 3.31 小组赛 A组 LGD vs VG
2018/04/01 DOTA
python服务器与android客户端socket通信实例
2014/11/12 Python
Python正则表达式匹配日期与时间的方法
2019/07/07 Python
python修改字典键(key)的方法
2019/08/05 Python
python是怎么被发明的
2020/06/15 Python
戴森西班牙官网:Dyson西班牙
2020/02/04 全球购物
大学生农村教师实习自我鉴定
2013/09/21 职场文书
服务口号大全
2014/06/11 职场文书
vue.js Router中嵌套路由的实用示例
2021/06/27 Vue.js
Python识别花卉种类鉴定网络热门植物并自动整理分类
2022/04/08 Python
oracle设置密码复杂度及设置超时退出的功能
2022/06/28 Oracle