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中通过ADO调用Asscess数据库和COM程序
Oct 09 PHP
php fputcsv命令 写csv文件遇到的小问题(多维数组连接符)
May 24 PHP
php中怎么搜索相关联数组键值及获取之
Oct 17 PHP
php+js iframe实现上传头像界面无跳转
Apr 29 PHP
神盾加密解密教程(一)PHP变量可用字符
May 28 PHP
跟我学Laravel之请求与输入
Oct 15 PHP
用PHP代码给图片加水印
Jul 01 PHP
如何使用纯PHP实现定时器任务(Timer)
Jul 31 PHP
php curl常用的5个经典例子
Jan 20 PHP
PHP实现对文件锁进行加锁、解锁操作的方法
Jul 04 PHP
php二维数组按某个键值排序的实例讲解
Feb 15 PHP
PHP设计模式之工厂模式(Factory Pattern)的讲解
Mar 21 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
Zend 输出产生XML解析错误
2009/03/03 PHP
PHP获取php,mysql,apche的版本信息示例代码
2014/01/16 PHP
PHP网络操作函数汇总
2015/05/18 PHP
php使用文本统计访问量的方法
2016/05/12 PHP
DWZ+ThinkPHP开发时遇到的问题分析
2016/12/12 PHP
PHP如何获取当前主机、域名、网址、路径、端口等参数
2017/06/09 PHP
JS解密入门之凭直觉解
2008/06/25 Javascript
javascript replace()正则替换实现代码
2010/02/26 Javascript
ExtJs扩展之GroupPropertyGrid代码
2010/03/05 Javascript
ExtJs使用IFrame的实现代码
2010/03/24 Javascript
基于jquery的滑动样例代码
2010/11/20 Javascript
dotopAlert 提示用户需安装播放器的代码
2012/09/17 Javascript
自动设置iframe大小的jQuery代码
2013/09/11 Javascript
jquery实现手风琴效果实例代码
2013/11/15 Javascript
Javascript字符串浏览器兼容问题分析
2014/12/01 Javascript
iOS和Android用同一个二维码实现跳转下载链接的方法
2016/09/28 Javascript
PHP抓取HTTPS内容和错误处理的方法
2016/09/30 Javascript
Vue开发过程中遇到的疑惑知识点总结
2017/01/20 Javascript
利用vue + element实现表格分页和前端搜索的方法
2017/12/25 Javascript
Vue实现todolist删除功能
2018/06/26 Javascript
ES6 新增的创建数组的方法(小结)
2019/08/01 Javascript
Python基类函数的重载与调用实例分析
2015/01/12 Python
Python设计模式之装饰模式实例详解
2019/01/21 Python
对python3 Serial 串口助手的接收读取数据方法详解
2019/06/12 Python
python里dict变成list实例方法
2019/06/26 Python
Python实现朴素贝叶斯的学习与分类过程解析
2019/08/24 Python
Python下应用opencv 实现人脸检测功能
2019/10/24 Python
应届生人事助理求职信
2013/11/09 职场文书
外语系毕业生自荐信范文
2013/12/16 职场文书
活动总结的格式
2014/05/07 职场文书
课外小组活动总结
2014/08/27 职场文书
质检员工作总结2015
2015/04/25 职场文书
学籍证明模板
2015/06/18 职场文书
MySQL系列之七 MySQL存储引擎
2021/07/02 MySQL
JavaScript分页组件使用方法详解
2021/07/26 Javascript
JavaScript 对象创建的3种方法
2021/11/17 Javascript