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中在数据库中保存Checkbox数据(1)
Oct 09 PHP
PHP编程之高级技巧——利用Mysql函数
Oct 09 PHP
PHP和.net中des加解密的实现方法
Feb 27 PHP
深入PHP许愿墙模块功能分析
Jun 25 PHP
PHP stream_context_create()函数的使用示例
May 12 PHP
PHP简单遍历对象示例
Sep 28 PHP
基于thinkPHP框架实现留言板的方法
Oct 17 PHP
php实现有序数组打印或排序的方法【附Python、C及Go语言实现代码】
Nov 10 PHP
PHP进程通信基础之信号量与共享内存通信
Feb 19 PHP
利用PHPExcel读取Excel的数据和导出数据到Excel
May 12 PHP
Laravel程序架构设计思路之使用动作类
Jun 07 PHP
php的扩展写法总结
May 14 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
一个SQL管理员的web接口
2006/10/09 PHP
linux系统上支持php的 iconv()函数的方法
2011/10/01 PHP
php ci框架验证码实例分析
2013/06/26 PHP
javascript 动态table添加colspan\rowspan 参数的方法
2009/07/25 Javascript
我用的一些Node.js开发工具、开发包、框架等总结
2014/09/25 Javascript
js获取UserControl内容为拼html时提供方便
2014/11/02 Javascript
javascript感应鼠标图片透明度显示的方法
2015/02/24 Javascript
详解js中构造流程图的核心技术JsPlumb(2)
2015/12/08 Javascript
Markdown与Bootstrap相结合实现图片自适应属性
2016/05/04 Javascript
Jquery+Ajax+xml实现中国地区选择三级联动菜单效果(推荐)
2017/06/09 jQuery
微信小程序倒计时功能实例代码
2018/07/17 Javascript
详解如何在vue项目中使用layui框架及采坑
2019/05/05 Javascript
Vue项目中使用jsonp抓取跨域数据的方法
2019/11/10 Javascript
jQuery AJAX应用实例总结
2020/05/19 jQuery
JS实现可以用键盘方向键控制的动画
2020/12/11 Javascript
Element el-button 按钮组件的使用详解
2021/02/01 Javascript
[05:06]TI4西雅图DOTA2前线报道 海涛密探LGD训练
2014/07/09 DOTA
Python中删除文件的程序代码
2011/03/13 Python
python2.7无法使用pip的解决方法(安装easy_install)
2018/04/03 Python
python爬取内容存入Excel实例
2019/02/20 Python
python循环定时中断执行某一段程序的实例
2019/06/29 Python
详解Python打包分发工具setuptools
2019/08/05 Python
感知器基础原理及python实现过程详解
2019/09/30 Python
opencv-python 提取sift特征并匹配的实例
2019/12/09 Python
Python实现bilibili时间长度查询的示例代码
2020/01/14 Python
HTML5自定义data-* data(obj)属性和jquery的data()方法的使用
2012/12/13 HTML / CSS
世界上最大的糖果店:Dylan’s Candy Bar
2017/11/07 全球购物
String s = new String(“xyz”);创建了几个String Object?
2015/08/05 面试题
电子商务自荐书范文
2014/01/04 职场文书
酒店保安员岗位职责
2014/01/31 职场文书
《放飞蜻蜓》教学反思
2014/04/27 职场文书
明星邀请函
2015/02/02 职场文书
2015年班长个人工作总结
2015/04/03 职场文书
2016党员干部反腐倡廉心得体会
2016/01/13 职场文书
Python读取文件夹下的所有文件实例代码
2021/04/02 Python
通过T-SQL语句创建游标与实现数据库加解密功能
2022/03/16 SQL Server