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 相关文章推荐
初探PHP5
Oct 09 PHP
php数组函数序列之prev() - 移动数组内部指针到上一个元素的位置,并返回该元素值
Oct 31 PHP
PHP间隔一段时间执行代码的方法
Dec 02 PHP
php获取用户浏览器版本的方法
Jan 03 PHP
Yii2 rbac权限控制之rule教程详解
Jun 23 PHP
Yii数据读取与跳转参数传递用法实例分析
Jul 12 PHP
PHP序列化操作方法分析
Sep 28 PHP
php微信公众号开发(3)php实现简单微信文本通讯
Dec 15 PHP
Yii2实现UploadedFile上传文件示例
Feb 15 PHP
PHP中Session ID的实现原理实例分析
Aug 17 PHP
laravel 修改记住我功能的cookie保存时间的方法
Oct 14 PHP
PHP7 标准库修改
Mar 09 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 error_log()将错误信息写入一个文件(定义和用法)
2013/10/25 PHP
WIFI万能钥匙密码查询接口实例
2015/09/28 PHP
php使用curl实现简单模拟提交表单功能
2017/05/15 PHP
Save a File Using a File Save Dialog Box
2007/06/18 Javascript
jqgrid 简单学习笔记
2011/05/03 Javascript
jQuery 中使用JSON的实现代码
2011/12/01 Javascript
什么是DOM(Document Object Model)文档对象模型
2012/03/05 Javascript
js读取注册表的键值示例
2013/09/25 Javascript
JS设置获取cookies的方法
2014/01/26 Javascript
Jquery中Event对象属性小结
2015/02/27 Javascript
Bootstrap基础学习
2015/06/16 Javascript
使用coffeescript编写node.js项目的方法汇总
2015/08/05 Javascript
jquery easyUI中ajax异步校验用户名
2016/08/19 Javascript
ES6使用let命令更简单的实现块级作用域实例分析
2017/03/31 Javascript
深入理解JavaScript继承的多种方式和优缺点
2017/05/12 Javascript
Ext JS 实现建议词模糊动态搜索功能
2017/05/13 Javascript
原生JS+Canvas实现五子棋游戏实例
2017/06/19 Javascript
JavaScript实现职责链模式概述
2018/01/25 Javascript
JavaScript对象的浅拷贝与深拷贝实例分析
2018/07/25 Javascript
Vue.js计算机属性computed和methods方法详解
2019/10/12 Javascript
element-ui 本地化使用教程详解
2019/10/28 Javascript
[02:25]DOTA2英雄基础教程 生死判决瘟疫法师
2013/12/06 DOTA
python去掉行尾的换行符方法
2017/01/04 Python
Python标准库shutil用法实例详解
2018/08/13 Python
pycharm运行程序时在Python console窗口中运行的方法
2018/12/03 Python
PyCharm设置每行最大长度限制的方法
2019/01/16 Python
python Django里CSRF 对应策略详解
2019/08/05 Python
对Django 转发和重定向的实例详解
2019/08/06 Python
Canvas实现放大镜效果完整案例分析(附代码)
2020/11/26 HTML / CSS
Hoover胡佛官网:美国吸尘器和洗地机品牌
2019/01/09 全球购物
Wolford法国官网:奥地利奢侈内衣品牌
2020/08/11 全球购物
遥感技术与仪器求职信
2014/02/22 职场文书
2014年教师节寄语
2014/08/11 职场文书
2015年技术员工作总结
2015/04/10 职场文书
创业开店,这样方式更合理
2019/08/26 职场文书
微信小程序实现轮播图指示器
2022/06/25 Javascript