突然看到这个,觉得很好,就拿过来了,如下:

//定义编码
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 header函数设置HTTP头的示例的更多相关文章

  1. PHP 使用header函数设置HTTP头的示例解析 表头

    PHP 使用header函数设置HTTP头的示例解析 表头 //定义编码 header( 'Content-Type:text/html;charset=utf-8 '); //Atom header ...

  2. (转载)PHP使用header函数设置HTTP头的示例方法表头

    (转载)http://justcoding.iteye.com/blog/601117/ 代码: //定义编码 header( 'Content-Type:text/html;charset=utf- ...

  3. PHP 使用header函数设置HTTP头的示例方法 表头 (xlsx下载)

    转载 http://justcoding.iteye.com/blog/601117/ //定义编码header( 'Content-Type:text/html;charset=utf-8 '); ...

  4. php header()函数设置页面Cache缓存

    header()函数在php的使用很大,下面我来介绍利用它实现页面缓存的一些方法,但使用header前必须注意,在它之前不能任何输出,包括空格. 手册上,我们对于cache都是写着如何设置,以便让代码 ...

  5. PHP header函数设置http报文头(设置头部域)

    PHP HTTP 简介: HTTP 函数允许您在其他输出被发送之前,对由 Web 服务器发送到浏览器的信息进行操作. PHP 5 HTTP 函数:header()     向客户端发送原始的 HTTP ...

  6. PHP header函数设置http报文头示例详解以及解决http返回头中content-length与Transfer-Encoding: chunked的问题

    最近在服务器上,多媒体与设备(摄像头)对接的时候,总是发生错误导致设备崩溃,抓包发现响应头不对,没有返回length,使得摄像头立即崩溃.找了一下资料,改了一下响应头就好了. //定义编码 heade ...

  7. PHP header函数设置http报文头示例详解

    //定义编码 header( 'Content-Type:text/html;charset=utf-8 '); //Atom header('Content-type: application/at ...

  8. PHP中的header()函数作用

    PHP 中 header()函数的作用是给客户端发送头信息. 什么是头信息?这里只作简单解释,详细的自己看http协议.在 HTTP协议中,服务器端的回答(response)内容包括两部分:头信息(h ...

  9. 最全面的AndroidStudio配置指南总结-包括护眼模式

    使用AndroidStudio开发APP已有半年多的时间了,从刚开始的不习惯到慢慢适应再到逐渐喜欢上AndroidStudio,中间的过程颇有一番曲折,现在把自己对AndroidStudio的配置心得 ...

随机推荐

  1. hdu Minimum Inversion Number(逆序数的小知识与线段树)

    飞! 题解 首先,求逆序数对的思路: 1.得到整个数列后,从前往后扫,统计比a[i]小的,在a[i]后面的有多少个 这样做的话,应该是只有n2的暴力作法,没想到更好的方法 2.统计a[i]前面的,且比 ...

  2. 计算机学院大学生程序设计竞赛(2015’12)The collector’s puzzle

    Problem Description There is a collector who own many valuable jewels. He has a problem about how to ...

  3. SHA_1计算消息摘要

    /** * SHA_1计算消息摘要 * @param bytes 待计算数据 * @return */ public static String SHA_1(byte[] bytes) { Strin ...

  4. Java中利用JFrame创建窗体

    1. 一个简单例子: public class Test(){ public static void main(String[] args){ JFrame frame = new JFrame(); ...

  5. bootstrap多选框

    不多说,先上图片 本多选框是用的bootstrap的样式为基础,将弹出框css改造,然后自己写的js得到. 下面为全部页面的代码,需要的可以自己改动js,得到自己需要的效果 <!DOCTYPE ...

  6. oracle截取字符串,定索引

    转载:https://www.cnblogs.com/qmfsun/p/4493918.html 使用Oracle中Instr()和substr()函数: 1 2 3 4 5 6 7 8 9 10 1 ...

  7. NMS_非极大值抑制(转)

    NMS(non maximum suppression),中文名非极大值抑制,在很多计算机视觉任务中都有广泛应用,如:边缘检测.目标检测等. 这里主要以人脸检测中的应用为例,来说明NMS,并给出Mat ...

  8. ubuntu 启动 ssh 服务

    $ sudo service ssh start $ sudo /etc/init.d/ssh start 重启 $ sudo /etc/init.d/ssh restart $ sudo servi ...

  9. virtualenv(for python)

    完整: http://docs.jinkan.org/docs/flask/installation.html#installation   virtualenv 你很可能想在开发中用上 virtua ...

  10. mac U盘安装盘制作

    以下面的版本为例: Install_macOS_Sierra_10.12.6.dmg 解压到桌面,然后打命令 sudo /Users/love/Desktop/Install\ macOS\ Sier ...