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 相关文章推荐
JAVA/JSP学习系列之七
Oct 09 PHP
一个php作的文本留言本的例子(一)
Oct 09 PHP
PHP的explode和implode的使用说明
Jul 17 PHP
php简单生成随机数的方法
Jul 30 PHP
ThinkPHP中使用Ueditor富文本编辑器
Sep 02 PHP
Yii使用技巧大汇总
Dec 29 PHP
PHP操作FTP类 (上传、下载、移动、创建等)
Mar 31 PHP
PHP微信开发之查询微信精选文章
Jun 23 PHP
将PHP的session数据存储到数据库中的代码实例
Jun 24 PHP
PHP 中常量的知识整理
Apr 14 PHP
基于php编程规范(详解)
Aug 17 PHP
PHP const定义常量及global定义全局常量实例解析
May 28 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
使用php4加速网络传输
2006/10/09 PHP
从零开始学YII2框架(三)扩展插件yii2-gird
2014/08/20 PHP
PHP排序算法之希尔排序(Shell Sort)实例分析
2018/04/20 PHP
PHP自动生成缩略图函数的源码示例
2019/03/18 PHP
PHP文件后缀不强制为.php方法
2019/03/31 PHP
js跑马灯代码(自写)
2013/04/17 Javascript
javascript父、子页面交互技巧总结
2014/08/08 Javascript
jQuery通过控制节点实现仅在前台通过get方法完成参数传递
2015/02/02 Javascript
JavaScript中的依赖注入详解
2015/03/18 Javascript
js实现改进的仿蓝色论坛导航菜单效果代码
2015/09/06 Javascript
javaScript数组迭代方法详解
2016/04/14 Javascript
Javascript的无new构建实例详解
2016/05/15 Javascript
Google 地图API资料整理及详细介绍
2016/08/06 Javascript
简单几步实现返回顶部效果
2016/12/05 Javascript
Vue.js实现多条件筛选、搜索、排序及分页的表格功能
2020/11/24 Javascript
微信小程序 出现47001 data format error原因解决办法
2017/03/10 Javascript
vue实现的下拉框功能示例
2019/01/29 Javascript
layui实现鼠标移动到单元格上显示数据的方法
2019/09/11 Javascript
python 远程统计文件代码分享
2015/05/14 Python
简单了解Python中的几种函数
2017/11/03 Python
Python向MySQL批量插数据的实例讲解
2018/03/31 Python
python库lxml在linux和WIN系统下的安装
2018/06/24 Python
Python为何不能用可变对象作为默认参数的值
2019/07/01 Python
详解Python打包分发工具setuptools
2019/08/05 Python
TensorFlow索引与切片的实现方法
2019/11/20 Python
python基于socket函数实现端口扫描
2020/05/28 Python
python 实现关联规则算法Apriori的示例
2020/09/30 Python
python使用matplotlib的savefig保存时图片保存不完整的问题
2021/01/08 Python
5 个强大的HTML5 API 函数推荐
2014/11/19 HTML / CSS
世界上第一个水枕头:Mediflow
2018/12/06 全球购物
Michael Kors英国官网:美国奢侈品品牌
2019/11/13 全球购物
《满井游记》教学反思
2014/02/26 职场文书
明信片寄语大全
2014/04/08 职场文书
公司请假条范文
2014/04/11 职场文书
乡镇精神文明建设汇报材料
2014/08/15 职场文书
5人制售《绝地求生》游戏外挂获利500多万元 被判刑
2022/03/31 其他游戏