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实现ping
Oct 09 PHP
php 实现进制转换(二进制、八进制、十六进制)互相转换实现代码
Oct 22 PHP
php 判断是否是中文/英文/数字示例代码
Sep 30 PHP
PHP fastcgi模式上传大文件(大约有300多K)报错
Sep 28 PHP
php jsonp单引号转义
Nov 23 PHP
PHP中防止SQL注入方法详解
Dec 25 PHP
php正则表达式学习笔记
Nov 13 PHP
php基于dom实现读取图书xml格式数据的方法
Feb 03 PHP
PHP INT类型在内存中占字节详解
Jul 20 PHP
使用Laravel中的查询构造器实现增删改查功能
Sep 03 PHP
php框架CI(codeigniter)自动加载与自主创建对象操作实例分析
Jun 06 PHP
php开发最强大的IDE编辑的phpstorm 2020.2配置Xdebug调试的详细教程
Aug 17 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
第十节--抽象方法和抽象类
2006/11/16 PHP
调整PHP的性能
2013/10/30 PHP
基于php实现七牛抓取远程图片
2015/12/01 PHP
Yii控制器中操作视图js的方法
2016/07/04 PHP
Yii2基于Ajax自动获取表单数据的方法
2016/08/10 PHP
Laravel5中Cookie的使用详解
2017/05/03 PHP
Laravel 5+ .env环境配置文件详解
2020/04/06 PHP
获取css样式表内样式的js函数currentStyle(IE),defaultView(FF)
2011/02/14 Javascript
深入document.write()与HTML4.01的非成对标签的详解
2013/05/08 Javascript
仿谷歌主页js动画效果实现代码
2013/07/14 Javascript
用JavaScript计算在UTF-8下存储字符串占用字节数
2013/08/08 Javascript
javascript中简单的进制转换代码实例
2013/10/26 Javascript
JS获取各种浏览器窗口大小的方法
2014/01/14 Javascript
基于编写jQuery的无缝滚动插件
2014/08/02 Javascript
JavaScript中的公有、私有、特权和静态成员用法分析
2014/11/20 Javascript
jQuery实现从身份证号中获取出生日期和性别的方法分析
2016/02/25 Javascript
Jquery实现的简单轮播效果【附实例】
2016/04/19 Javascript
JavaScript中的跨浏览器事件操作的基本方法整理
2016/05/20 Javascript
JS实现非首屏图片延迟加载的示例
2018/01/06 Javascript
JavaScript实现与使用发布/订阅模式详解
2019/01/19 Javascript
详释JavaScript执行环境与执行栈
2019/04/02 Javascript
js实现批量删除功能
2020/08/27 Javascript
[52:06]完美世界DOTA2联赛决赛日 Inki vs LBZS 第一场 11.08
2020/11/10 DOTA
[01:11:28]DOTA2-DPC中国联赛定级赛 RNG vs Phoenix BO3第一场 1月8日
2021/03/11 DOTA
python实现类之间的方法互相调用
2018/04/29 Python
使用pandas将numpy中的数组数据保存到csv文件的方法
2018/06/14 Python
Python3之不使用第三方变量,实现交换两个变量的值
2019/06/26 Python
对Pytorch中nn.ModuleList 和 nn.Sequential详解
2019/08/18 Python
Python如何实现邮件功能
2020/05/27 Python
使用Python爬取小姐姐图片(beautifulsoup法)
2021/02/11 Python
北美最大的手工艺品零售商之一:Michaels Stores
2019/02/27 全球购物
Java如何获得ResultSet的总行数
2016/09/03 面试题
领导证婚人证婚词
2014/01/13 职场文书
2015年汽车销售工作总结
2015/04/07 职场文书
2019行政前台转正申请书范文3篇
2019/08/15 职场文书
漫改真人电影「萌系男友是燃燃的橘色」公开先导视觉图
2022/03/21 日漫