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 相关文章推荐
Windows下的PHP5.0安装配制详解
Sep 05 PHP
PHP获取网卡地址的代码
Apr 09 PHP
php 动态多文件上传
Jan 18 PHP
php join函数应用
May 04 PHP
php无限分类且支持输出树状图的详细介绍
Jun 19 PHP
CI框架整合smarty步骤详解
May 19 PHP
PHP redis实现超迷你全文检索
Mar 04 PHP
PHP中的empty、isset、isnull的区别与使用实例
Mar 22 PHP
thinkPHP框架通过Redis实现增删改查操作的方法详解
May 13 PHP
php连接sftp的作用以及实例代码
Sep 23 PHP
php获取小程序码的实现代码(B类接口)
Jun 13 PHP
如何用PHP实现分布算法之一致性哈希算法
May 26 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 explode函数实例代码
2012/02/27 PHP
基于php socket(fsockopen)的应用实例分析
2013/06/02 PHP
php使用base64加密解密图片示例分享
2014/01/20 PHP
php字符串的替换,分割和连接方法
2016/05/23 PHP
浅谈php中curl、fsockopen的应用
2016/12/10 PHP
HTTP头隐藏PHP版本号实现过程解析
2020/12/09 PHP
JavaScript 数组的 uniq 方法
2008/01/23 Javascript
form表单中去掉默认的enter键提交并绑定js方法实现代码
2013/04/01 Javascript
javascript图片切换综合实例(循环切换、顺序切换)
2016/01/13 Javascript
Javascript生成带参数的二维码示例
2016/10/10 Javascript
微信小程序中显示html格式内容的方法
2017/04/25 Javascript
JavaScript中防止微信浏览器被整体拖动的方法
2017/08/25 Javascript
JS+jQuery实现注册信息的验证功能
2017/09/26 jQuery
让Vue也可以使用Redux的方法
2018/05/23 Javascript
vue 解决setTimeOut和setInterval函数无效报错的问题
2020/07/30 Javascript
小程序实现密码输入框
2020/11/16 Javascript
python实现每次处理一个字符的三种方法
2014/10/09 Python
收藏整理的一些Python常用方法和技巧
2015/05/18 Python
python实现逻辑回归的方法示例
2017/05/02 Python
numpy求平均值的维度设定的例子
2019/08/24 Python
简单了解python装饰器原理及使用方法
2019/12/18 Python
Python OpenCV读取显示视频的方法示例
2020/02/20 Python
python操作链表的示例代码
2020/09/27 Python
SteelSeries赛睿官网:游戏外设和配件的领先制造商(耳机、键盘、鼠标和鼠标垫)
2018/06/17 全球购物
描述RIP和OSPF区别以及特点
2015/01/17 面试题
军训教官感言
2014/03/02 职场文书
怎么写好自荐书
2014/03/02 职场文书
婚礼主持词开场白
2014/03/13 职场文书
销售目标责任书
2014/07/23 职场文书
寻找最美家庭活动方案
2014/08/20 职场文书
大学感恩节活动总结
2015/05/05 职场文书
python解决12306登录验证码的实现
2021/04/18 Python
解决MySQL存储时间出现不一致的问题
2021/04/28 MySQL
Jpa Specification如何实现and和or同时使用查询
2021/11/23 Java/Android
springboot 自定义配置 解决Boolean属性不生效
2022/03/18 Java/Android
在windows server 2012 r2中安装mysql的详细步骤
2022/07/23 Servers