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/ZendEngine2的改进
Oct 09 PHP
PHP操作数组的一些函数整理介绍
Jul 17 PHP
PHP类与对象中的private访问控制的疑问
Nov 01 PHP
PHP捕获Fatal error错误的方法
Jun 11 PHP
yii实现创建验证码实例解析
Jul 31 PHP
PHP遍历数组的三种方法及效率对比分析
Feb 12 PHP
标准PHP的AES加密算法类
Mar 12 PHP
Yii2实现让关联字段支持搜索功能的方法
Aug 10 PHP
老生常谈php 正则中的i,m,s,x,e分别表示什么
Mar 02 PHP
php支付宝APP支付功能
Jul 29 PHP
laravel 验证错误信息到 blade模板的方法
Sep 29 PHP
laravel dingo API返回自定义错误信息的实例
Sep 29 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代码
2008/04/09 PHP
PHP使用CURL获取302跳转后的地址实例
2014/05/04 PHP
PHP编程开发怎么提高编程效率 提高PHP编程技术
2015/11/09 PHP
Win10 下安装配置IIS + MySQL + nginx + php7.1.7
2017/08/04 PHP
jQuery1.6 使用方法一
2011/11/23 Javascript
基于jquery的跟随屏幕滚动代码
2012/07/24 Javascript
JavaScript window.document的属性、方法和事件小结
2012/10/24 Javascript
JavaScript中的alert()函数使用技巧详解
2014/12/29 Javascript
jquery文档操作wrap()方法实例简述
2015/01/10 Javascript
JavaScript实现点击文字切换登录窗口的方法
2015/05/11 Javascript
jquery中val()方法是从最后一个选项往前读取的
2015/09/06 Javascript
bootstrap模态框跳转到当前模板页面 框消失了而背景存在问题的解决方法
2020/11/30 Javascript
利用浮层使select不可选的实现方法
2016/12/03 Javascript
清除输入框内的空格
2016/12/21 Javascript
微信小程序 video详解及简单实例
2017/01/16 Javascript
让微信小程序支持ES6中Promise特性的方法详解
2017/06/13 Javascript
Angular4.x Event (DOM事件和自定义事件详解)
2018/10/09 Javascript
详解es6新增数组方法简便了哪些操作
2019/05/09 Javascript
javascript实现动态时钟的启动和停止
2020/07/29 Javascript
手把手带你搭建一个node cli的方法示例
2020/08/07 Javascript
python实现读取命令行参数的方法
2015/05/22 Python
Python脚本实现12306火车票查询系统
2016/09/30 Python
python实现超市扫码仪计费
2018/05/30 Python
Django框架实现逆向解析url的方法
2018/07/04 Python
python绘制多个曲线的折线图
2020/03/23 Python
详解Python 正则表达式模块
2018/11/05 Python
WxPython建立批量录入框窗口
2019/02/27 Python
python中的subprocess.Popen()使用详解
2019/12/25 Python
Python使用pyyaml模块处理yaml数据
2020/04/14 Python
Python插件机制实现详解
2020/05/04 Python
夏威夷咖啡公司:Hawaii Coffee Company
2019/09/19 全球购物
全球最大运动品牌的男装、女装和童装官方库存商:A&A Sports
2021/01/17 全球购物
财务信息服务专业自荐书范文
2014/02/08 职场文书
教师自查自纠工作情况报告
2014/10/29 职场文书
2014幼儿园小班工作总结
2014/11/10 职场文书
优秀教师事迹材料
2014/12/15 职场文书