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 相关文章推荐
PHP教程 预定义变量
Oct 23 PHP
yii框架表单模型使用及以数组形式提交表单数据示例
Apr 30 PHP
PHP APC配置文件2套和参数详解
Jun 11 PHP
采用thinkphp自带方法生成静态html文件详解
Jun 13 PHP
php用户注册时常用的检验函数实例总结
Dec 22 PHP
PHP中文编码小技巧
Dec 25 PHP
详解PHP的Yii框架中自带的前端资源包的使用
Mar 31 PHP
Eclipse PHPEclipse 配置的具体步骤
Aug 08 PHP
PHP实现的回溯算法示例
Aug 15 PHP
PHP去除空数组且数组键名重置的讲解
Feb 28 PHP
PHP实现字符串的全排列详解
Apr 24 PHP
Yii框架响应组件用法实例分析
Sep 04 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
收音机术语解释
2021/03/01 无线电
比较简单实用的PHP无限分类源码分享(思路不错)
2011/10/13 PHP
非常实用的php弹出错误警告函数扩展性强
2014/01/17 PHP
PHP关于htmlspecialchars、strip_tags、addslashes的解释
2014/07/04 PHP
ThinkPHP实例化模型的四种方法概述
2014/08/22 PHP
PHP基于回溯算法解决n皇后问题的方法示例
2017/11/07 PHP
javascript编程起步(第四课)
2007/02/27 Javascript
Javascript 自定义类型方法小结
2010/03/02 Javascript
js中判断控件是否存在
2010/08/25 Javascript
基于MooTools的很有创意的滚动条时钟动画
2010/11/14 Javascript
jquery.tmpl JQuery模板插件
2011/10/10 Javascript
JS实现点击按钮自动增加一个单元格的方法
2015/03/09 Javascript
用JavaScript实现对话框的教程
2015/06/04 Javascript
JavaScript获取IP获取的是IPV6 如何校验
2016/06/12 Javascript
JS中的作用域链
2017/03/01 Javascript
javascript 日期相减-在线教程(附代码)
2017/08/17 Javascript
vuejs选中当前样式active的实例
2018/08/22 Javascript
Vue 事件处理操作实例详解
2019/03/05 Javascript
从理论角度讨论JavaScript闭包
2019/04/03 Javascript
聊聊Vue中provide/inject的应用详解
2019/11/10 Javascript
vue表单验证之禁止input输入框输入空格
2020/12/03 Vue.js
python实现读取命令行参数的方法
2015/05/22 Python
Django与遗留的数据库整合的方法指南
2015/07/24 Python
在scrapy中使用phantomJS实现异步爬取的方法
2018/12/17 Python
django表单的Widgets使用详解
2019/07/22 Python
深入解析神经网络从原理到实现
2019/07/26 Python
详解Django3中直接添加Websockets方式
2020/02/12 Python
详解matplotlib中pyplot和面向对象两种绘图模式之间的关系
2021/01/22 Python
美国亚马逊旗下男装网站:East Dane(支持中文)
2019/09/25 全球购物
食品业务员岗位职责
2014/03/18 职场文书
班级旅游计划书
2014/05/03 职场文书
新员工试用期工作总结2015
2015/05/28 职场文书
小学运动会开幕词
2016/03/04 职场文书
2019年大学推荐信
2019/06/24 职场文书
教你快速开启Apache SkyWalking的自监控
2021/04/25 Servers
windows10 家庭版下FTP服务器搭建教程
2022/08/05 Servers