header常用指令

header分为三部分:

第一部分为HTTP协议的版本(HTTP-Version);

第二部分为状态代码(Status);

第三部分为原因短语(Reason-Phrase)。

// fix 404 pages:   用这个header指令来解决URL重写产生的404 header

header('HTTP/1.1 200 OK');

// set 404 header:   页面没找到

header('HTTP/1.1 404 Not Found');

//页面被永久删除,可以告诉搜索引擎更新它们的urls

// set Moved Permanently header (good for redrictions)  

// use with location header  

header('HTTP/1.1 301 Moved Permanently');

// 访问受限

header('HTTP/1.1 403 Forbidden');

// 服务器错误

header('HTTP/1.1 500 Internal Server Error');

// 重定向到一个新的位置

// 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';

// 覆盖 X-Powered-By value

// override X-Powered-By: PHP:  

header('X-Powered-By: PHP/4.4.0');  

header('X-Powered-By: Brain/0.6b');

// 内容语言 (en = English)

// 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');

// 显示登录对话框,可以用来进行HTTP认证

// 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';?>

// 发送一个200 正常响应

header("HTTP/1.1 200 OK");

// 发送一个404 找不到资源响应

header('HTTP/1.1 404 Not Found');

// 发送一个301 永久重定向

header('HTTP/1.1 301 Moved Permanently');

// 发送一个503 网站暂时不能访问

header('HTTP/1.1 503 Service Temporarily Unavailable');

// 网页重定向

header('Location: http://www.jb51.net');

// 设置网页3秒后重定向

header('Refresh: 3; url=http://www.jb51.net');

echo '网页将在3秒后跳转到http://www.jb51.net';

// 设置网页编码

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

// 设置网页输出一个图片流

header('Content-Type: image/jpeg');

// 设置网页输出一个pdf文档

header('Content-Type: application/pdf');

// 设置网页输出一个zip文档

header('Content-Type: application/zip');

详细出处参考:http://www.jb51.net/article/38024.htm

基于header的一些常用指令详解的更多相关文章

  1. ImageMagick常用指令详解

    Imagemagick常用指令 (ImageMagick--蓝天白云) (ImageMagick官网) (其他比较有价值的IM参考) (图片自动旋转的前端实现方案) convert 转换图像格式和大小 ...

  2. Vue入门---常用指令详解

    Vue入门 Vue是一个MVVM(Model / View / ViewModel)的前端框架,相对于Angular来说简单.易学上手快,近两年也也别流行,发展速度较快,已经超越Angular了.比较 ...

  3. Vue常用指令详解分析

    Vue入门 Vue是一个MVVM(Model / View / ViewModel)的前端框架,相对于Angular来说简单.易学上手快,近两年也也别流行,发展速度较快,已经超越Angular了.比较 ...

  4. Nginx核心配置文件常用参数详解

    Nginx核心配置文件常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 关于Nginx权威文档的话童鞋们可以参考Nginx官方文档介绍:http://nginx.org/ ...

  5. curl常用选项详解

    curl常用选项详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 又是下班的时间了,让我们一起来学习一下今天的Linux命令吧~我一半只把自己常用的参数列出来,其他的有但是我们几 ...

  6. Ansible安装部署及常用模块详解

    Ansible命令使用 Ansible语法使用ansible <pattern_goes_here> -m <module_name> -a <arguments> ...

  7. find常用参数详解

    find常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在linux系统中,在init 3模式情况下都是命令行模式,这个时候我们想要找到一个文件的就得依赖一个非常好用的 ...

  8. samtools常用命令详解(转)

    转自:samtools常用命令详解 samtools的说明文档:http://samtools.sourceforge.net/samtools.shtml samtools是一个用于操作sam和ba ...

  9. #pragma 预处理指令详解

    源地址:http://blog.csdn.net/jx_kingwei/article/details/367312 #pragma  预处理指令详解              在所有的预处理指令中, ...

随机推荐

  1. 微信企业号接收消息(使用SpringMVC)

    微信企业号接收消息(使用SpringMVC) 微信企业号接收消息(使用SpringMVC) 将应用设置在回调模式时,企业可以通过回调URL接收员工回复的消息,以及员工关注.点击菜单.上报地理位置等事件 ...

  2. SEO-友情链接注意事项

    为什么要专门给友链一个区域呢?由此就可以想象到友情链接对一个网站有多重要前期,网站没有权重的时候,跟别人换友链,人家基本是不会换的因为你网站没权重,加了友链他也获取不到权重,对网站没有多少好处一般我们 ...

  3. C# 6 与 .NET Core 1.0 高级编程 - 41 ASP.NET MVC(中)

    译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 41 ASP.NET MVC(中)),不对的地方欢迎指出与交流. 章节出自<Professional C# ...

  4. 单发邮箱 群发邮箱 程序 Email winform

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  5. vue学习笔记 概述(一)

    vue里 最常见的 最普遍的用法 应该是 var app = new Vue({ el: '#app', data: { message: 'Hello Vue!' }}) 下面把所有使用方法尽可能列 ...

  6. Jquery EasyUI远程校验,Jquery EasyUI多个自定义校验,EasyUI自定义校验

    >>>>>>>>>>>>>>>>>>>>>>>>> ...

  7. 初窥DB2之insert语句

    第一种写法 INSERT INTO PERSVALUES (12, 'Harris', 20, 'Sales', 5, 18000, 1000, '1950-1-1') 第二种写法 INSERT IN ...

  8. rancher api key

    rancher将docker容器的界面化做的很好了,但是我们有时间需要在别的地方查看容器的一些信息,怎么办呢? rancher自己提供的有api 点击api查看 我们能够查看到该容器的一些信息,实际上 ...

  9. H5学习的第三周

    上周,我们结束了京东站的制作,本周我们开始了手机站和响应式网站的学习,并仿制了一个手机端界面和一个响应式界面,在完成这两个网站的过程中我遇到了许多问题,也了解了它们的解决方法,接下来我讲详细介绍本周我 ...

  10. cooking构建工具报错MSBUILD :error MSB4132解决办法

    最近学习cooking构建工具的时候,在自己的笔记本上运行的好好的,项目在公司电脑上clone下来的时候,发现构建报错,逐条查错,试了好多方法也不行 最后在github上找到了答案,只是之前一直没找到 ...