PHP header()函数常用方法总结


Posted in PHP onApril 11, 2014

//定义编码

header( 'Content-Type:text/html;charset=utf-8 ');

//Atom
header('Content-type: application/atom+xml');

//CSS
header('Content-type: text/css');

//Javascript
header('Content-type: text/javascript');

//JPEG Image
header('Content-type: image/jpeg');

//JSON
header('Content-type: application/json');

//PDF
header('Content-type: application/pdf');

//RSS
header('Content-Type: application/rss+xml; charset=ISO-8859-1');

//Text (Plain)
header('Content-type: text/plain');

//XML
header('Content-type: text/xml');

// ok
header('HTTP/1.1 200 OK');

//设置一个404头:
header('HTTP/1.1 404 Not Found');

//设置地址被永久的重定向
header('HTTP/1.1 301 Moved Permanently');

//转到一个新地址
header('Location: http://www.example.org/');

//文件延迟转向:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';
//当然,也可以使用html语法实现
// <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');

//文档语言
header('Content-language: en');

//告诉浏览器最后一次修改时间
$time = time() - 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');

//告诉浏览器文档内容没有发生改变
header('HTTP/1.1 304 Not Modified');

//设置内容长度
header('Content-Length: 1234');

//设置为一个下载类型
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');

// 对当前文档禁用缓存
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 past
header('Pragma: no-cache');

//设置内容类型:
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain'); //纯文本格式
header('Content-Type: image/jpeg'); //JPG***
header('Content-Type: application/zip'); // ZIP文件
header('Content-Type: application/pdf'); // PDF文件
header('Content-Type: audio/mpeg'); // 音频文件
header('Content-Type: application/x-shockw**e-flash'); //Flash动画

//显示登陆对话框
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 高手之路(一)
Oct 09 PHP
一个简易需要注册的留言版程序
Oct 09 PHP
第四章 php数学运算
Dec 30 PHP
Notice: Trying to get property of non-object problem(PHP)解决办法
Mar 11 PHP
PHP 第三节 变量介绍
Apr 28 PHP
析构函数与php的垃圾回收机制详解
Oct 28 PHP
php自定义hash函数实例
May 05 PHP
php使用glob函数遍历文件和目录详解
Sep 23 PHP
PHP使用PHPExcel实现批量上传到数据库的方法
Jun 08 PHP
Laravel 默认邮箱登录改成用户名登录的实现方法
Aug 12 PHP
浅析PHP反序列化中过滤函数使用不当导致的对象注入问题
Feb 15 PHP
PHP 8新特性简介
Aug 18 PHP
开源php中文分词系统SCWS安装和使用实例
Apr 11 #PHP
PHP获取网页标题的3种实现方法代码实例
Apr 11 #PHP
PHP动态生成javascript文件的2个例子
Apr 11 #PHP
php实现数组筛选奇数和偶数示例
Apr 11 #PHP
php求正负数数组中连续元素最大值示例
Apr 11 #PHP
PHP入门经历和学习过程分享
Apr 11 #PHP
Session的工作机制详解和安全性问题(PHP实例讲解)
Apr 10 #PHP
You might like
php结合正则获取字符串中数字
2015/06/19 PHP
php 查找数组元素提高效率的方法详解
2017/05/05 PHP
PHP后期静态绑定之self::限制实例分析
2018/12/21 PHP
JQuery 风格的HTML文本转义
2009/07/01 Javascript
js函数调用常用方法详解
2012/12/03 Javascript
jquery实现表格奇数偶数行不同样式(有图为证及实现代码)
2013/01/23 Javascript
得到jQuery detach()后节点中的某个值实现代码
2013/02/05 Javascript
Javascript 浮点运算精度问题分析与解决
2014/03/26 Javascript
JavaScript两种跨域技术全面介绍
2014/04/16 Javascript
JavaScript学习笔记之基础语法
2015/01/22 Javascript
使用jquery清空、复位整个输入域
2015/04/02 Javascript
JavaScript实现DOM对象选择器
2016/09/24 Javascript
nodejs服务搭建教程 nodejs访问本地站点文件
2017/04/07 NodeJs
Jquery获取radio选中的值
2017/05/05 jQuery
vuejs 切换导航条高亮(路由菜单高亮)的方法示例
2018/05/29 Javascript
npm配置国内镜像资源+淘宝镜像的方法
2018/09/07 Javascript
详解微信小程序图片地扯转base64解决方案
2019/08/18 Javascript
vue 动态表单开发方法案例详解
2019/12/02 Javascript
Python编写简单的HTML页面合并脚本
2016/07/11 Python
Python实现在线音乐播放器
2017/03/03 Python
Python实现PS滤镜功能之波浪特效示例
2018/01/26 Python
把vgg-face.mat权重迁移到pytorch模型示例
2019/12/27 Python
tensorflow模型保存、加载之变量重命名实例
2020/01/21 Python
keras-siamese用自己的数据集实现详解
2020/06/10 Python
魅力惠奢品线上平台:MEI.COM
2016/11/29 全球购物
美国玩具公司:U.S.Toy
2018/05/19 全球购物
雅虎笔试题(字符串操作)
2015/03/24 面试题
珍珠奶茶店创业计划书
2014/01/11 职场文书
升旗仪式演讲稿
2014/05/08 职场文书
文明之星事迹材料
2014/05/09 职场文书
安全资料员岗位职责范本
2014/06/28 职场文书
群众路线党员个人剖析材料
2014/10/08 职场文书
立案决定书范文
2015/06/24 职场文书
vue的项目如何打包上线
2022/04/13 Vue.js
Win11 BitLocker 驱动器加密
2022/04/19 数码科技
Python Matplotlib绘制动画的代码详解
2022/05/30 Python