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中for循环语句的几种变型
Mar 16 PHP
让php处理图片变得简单 基于gb库的图片处理类附实例代码下载
May 17 PHP
php上传文件,创建递归目录的实例代码
Oct 18 PHP
php使用curl检测网页是否被百度收录的示例分享
Jan 31 PHP
php操作MongoDB类实例
Jun 17 PHP
php面向对象编程self和static的区别
May 08 PHP
Thinkphp框架中D方法与M方法的区别
Dec 23 PHP
PHP使用preg_split和explode分割textarea存放内容的方法分析
Jul 03 PHP
PHP实现的AES双向加密解密功能示例【128位】
Sep 03 PHP
phpStorm+XDebug+chrome 配置详解
Apr 01 PHP
ThinkPHP3.2框架自带分页功能实现方法示例
May 13 PHP
PHP中非常有用却鲜有人知的函数集锦
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
PHP 向右侧拉菜单实现代码,测试使用中
2009/11/03 PHP
php 学习资料零碎东西
2010/12/04 PHP
兼容性最强的PHP生成缩略图的函数代码(修改版)
2011/01/18 PHP
PHP中几个可以提高运行效率的代码写法、技巧分享
2014/08/21 PHP
php版微信开发之接收消息,自动判断及回复相应消息的方法
2016/09/23 PHP
PHP常用字符串函数用法实例总结
2020/06/04 PHP
javascript实现日历控件(年月日关闭按钮)
2012/12/12 Javascript
深入剖析JavaScript:Object类型
2016/05/10 Javascript
关于json字符串与实体之间的严格验证代码
2016/11/10 Javascript
JSON键值对序列化和反序列化解析
2017/01/24 Javascript
关于Vue实现组件信息的缓存问题
2017/08/23 Javascript
Node.js使用Koa搭建 基础项目
2018/01/08 Javascript
AngularJS自定义表单验证功能实例详解
2018/08/24 Javascript
JS/HTML5游戏常用算法之碰撞检测 包围盒检测算法详解【圆形情况】
2018/12/13 Javascript
使用koa2创建web项目的方法步骤
2019/03/12 Javascript
微信小程序常用的3种提示弹窗实现详解
2019/09/19 Javascript
微信小程序自定义导航栏(模板化)
2019/11/15 Javascript
TensorFlow实现MLP多层感知机模型
2018/03/09 Python
python实现浪漫的烟花秀
2019/01/30 Python
Python中一般处理中文的几种方法
2019/03/06 Python
python操作小程序云数据库实现简单的增删改查功能
2019/06/06 Python
python实现图像全景拼接
2020/03/27 Python
使用python批量转换文件编码为UTF-8的实现
2020/04/03 Python
Python调用ffmpeg开源视频处理库,批量处理视频
2020/11/16 Python
利用Python将多张图片合成视频的实现
2020/11/23 Python
原装进口全世界:天猫国际
2016/08/03 全球购物
美国当红的名品折扣网:Gilt Groupe
2016/08/15 全球购物
Optimalprint加拿大:在线打印服务
2020/04/03 全球购物
党校培训自我鉴定
2014/02/01 职场文书
收银员的岗位职责范本
2014/02/04 职场文书
母亲节感恩寄语
2014/02/21 职场文书
2014年化验员工作总结
2014/11/18 职场文书
大学生村官驻村工作心得体会
2016/01/23 职场文书
Nginx 过滤静态资源文件的访问日志的实现
2021/03/31 Servers
多表查询、事务、DCL
2021/04/05 MySQL
Zabbix对Kafka topic积压数据监控的问题(bug优化)
2022/07/07 Servers