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 相关文章推荐
第七节--类的静态成员
Nov 16 PHP
php下使用SMTP发邮件的代码
Jan 10 PHP
PHP调用Twitter的RSS的实现代码
Mar 10 PHP
php教程 插件机制在PHP中实现方案
Nov 02 PHP
php class中self,parent,this的区别以及实例介绍
Apr 24 PHP
浅析PHP中Collection 类的设计
Jun 21 PHP
php去掉URL网址中带有PHPSESSID的配置方法
Jul 08 PHP
Yii使用CLinkPager分页实例详解
Jul 23 PHP
jQuery+PHP发布的内容进行无刷新分页(Fckeditor)
Oct 22 PHP
PHP函数import_request_variables()用法分析
Apr 02 PHP
AJAX PHP无刷新form表单提交的简单实现(推荐)
Sep 09 PHP
PHP从数组中删除元素的四种方法实例
May 12 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创建基本身份认证站点的方法详解
2013/06/08 PHP
php文件上传的简单实例
2013/10/19 PHP
php 伪造ip以及url来路信息方法汇总
2014/11/25 PHP
php+jQuery实现的三级导航栏下拉菜单显示效果
2017/08/10 PHP
PHP双向链表定义与用法示例
2018/01/31 PHP
ExtJS 设置级联菜单的默认值
2010/06/13 Javascript
Jquery中显示隐藏的实现代码分析
2011/07/26 Javascript
jQuery load方法用法集锦
2011/12/06 Javascript
js获取TreeView控件选中节点的Text和Value值的方法
2012/11/24 Javascript
javascript中的if语句使用介绍
2013/11/20 Javascript
jquery中$(#form :input)与$(#form input)的区别
2014/08/18 Javascript
js实现将选中值累加到文本框的方法
2015/08/12 Javascript
jQuery实现手机自定义弹出输入框
2016/06/13 Javascript
浅谈JS中的三种字符串连接方式及其性能比较
2016/09/02 Javascript
Javascrip实现文字跳动特效
2016/11/27 Javascript
浅述节点的创建及常见功能的实现
2016/12/15 Javascript
Vue自定义指令拖拽功能示例
2017/02/17 Javascript
一篇文章让你彻底弄懂JS的事件冒泡和事件捕获
2017/08/14 Javascript
详解tween.js的使用教程
2017/09/14 Javascript
深入浅出理解JavaScript高级定时器原理与用法
2018/08/02 Javascript
JavaScript学习笔记之基于定时器实现图片无缝滚动功能详解
2019/01/09 Javascript
jQuery实现弹幕特效
2019/11/29 jQuery
layui实现显示数据表格、搜索和修改功能示例
2020/06/03 Javascript
vue组件是如何解析及渲染的?
2021/01/13 Vue.js
python检查指定文件是否存在的方法
2015/07/06 Python
详细分析python3的reduce函数
2017/12/05 Python
对Python中Iterator和Iterable的区别详解
2018/10/18 Python
python rsync服务器之间文件夹同步脚本
2019/08/29 Python
大数据分析用java还是Python
2020/07/06 Python
如何将json数据转换为python数据
2020/09/04 Python
SQL面试题
2013/04/30 面试题
求职信范文英文版
2014/01/05 职场文书
公司领导班子民主生活会对照检查材料
2014/10/02 职场文书
个人作风建设自查报告
2014/10/22 职场文书
2014年网管工作总结
2014/12/11 职场文书
解决Pytorch中关于model.eval的问题
2021/05/22 Python