基于header的一些常用指令详解
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的一些常用指令详解的更多相关文章
- ImageMagick常用指令详解
Imagemagick常用指令 (ImageMagick--蓝天白云) (ImageMagick官网) (其他比较有价值的IM参考) (图片自动旋转的前端实现方案) convert 转换图像格式和大小 ...
- Vue入门---常用指令详解
Vue入门 Vue是一个MVVM(Model / View / ViewModel)的前端框架,相对于Angular来说简单.易学上手快,近两年也也别流行,发展速度较快,已经超越Angular了.比较 ...
- Vue常用指令详解分析
Vue入门 Vue是一个MVVM(Model / View / ViewModel)的前端框架,相对于Angular来说简单.易学上手快,近两年也也别流行,发展速度较快,已经超越Angular了.比较 ...
- Nginx核心配置文件常用参数详解
Nginx核心配置文件常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 关于Nginx权威文档的话童鞋们可以参考Nginx官方文档介绍:http://nginx.org/ ...
- curl常用选项详解
curl常用选项详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 又是下班的时间了,让我们一起来学习一下今天的Linux命令吧~我一半只把自己常用的参数列出来,其他的有但是我们几 ...
- Ansible安装部署及常用模块详解
Ansible命令使用 Ansible语法使用ansible <pattern_goes_here> -m <module_name> -a <arguments> ...
- find常用参数详解
find常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在linux系统中,在init 3模式情况下都是命令行模式,这个时候我们想要找到一个文件的就得依赖一个非常好用的 ...
- samtools常用命令详解(转)
转自:samtools常用命令详解 samtools的说明文档:http://samtools.sourceforge.net/samtools.shtml samtools是一个用于操作sam和ba ...
- #pragma 预处理指令详解
源地址:http://blog.csdn.net/jx_kingwei/article/details/367312 #pragma 预处理指令详解 在所有的预处理指令中, ...
随机推荐
- eclipse和myeclipse设置默认编码格式为UTF-8
1:jsp页面设置默认为utf-8 以eclipse为例 2:java界面设置: Window->Preferences->General->Workspace 面板Text fil ...
- python计算文件夹大小(linux du命令 简化版)
C盘又满了,怎么办?用了一些垃圾清理软件(或者bat脚本),但是还是不理想,那么具体哪些文件夹下面有巨大的文件呢?windows并不能通过详细信息看到每个文件夹的大小(PS:这里所谓的文件夹的大小是指 ...
- java初学代码,还不太熟练
奇数和 public class Homework01{ public static void main(String [] args){ long t=1,s=0; do{ s=s+t; t= ...
- Layoutinlater 转
http://blog.csdn.net/guolin_blog/article/details/12921889
- PHP的错误处理
PHP的错误处理机制 php的错误处理是比较复杂的, 本文讲解php中所有错误相关的重要知识点做一次梳理, 便于理解php的错误机制. 基础知识 在此之前, 先熟悉一下php error的基础知识 预 ...
- 从编译安装Keepalived 到 配置 负载均衡(LVS-DR)
最近在研究服务器高可用集群 (HA)…… Keepalived 是用C写的软路由.提供负载均衡与高可用特性. 负载均衡利用IPVS技术 高可用通过VRRP协议实现 更难能的贵的是,一直到最近还在更新 ...
- Docx组件读写Word文档介绍
Docx介绍 官方原文:DocX is a .NET library that allows developers to manipulate Word 2007/2010/2013 files, i ...
- jumpserver跳板机
一.安装依赖包 yum -y install epel-release yum clean all && yum makecache yum -y update yum -y inst ...
- 深度学习实践系列(2)- 搭建notMNIST的深度神经网络
如果你希望系统性的了解神经网络,请参考零基础入门深度学习系列,下面我会粗略的介绍一下本文中实现神经网络需要了解的知识. 什么是深度神经网络? 神经网络包含三层:输入层(X).隐藏层和输出层:f(x) ...
- C#调用webbrowser,阻止弹出新IE窗口
本人是用WPF内嵌 winform的webbrowser这种形式开发, 弹出的 //屏蔽弹出新IE窗口 private void webBrowser_NewWindow(object sender, ...