客户机的请求方式格式:是统一资源标识符、协议版本号,后边是MIME信息包括请求修饰符、客户机信息和可能的内容!服务器响应格式:一个状态行包括信息的协议版本号、一个成功或错误的代码,后边是MIME信息包括服务器信息、实体信息和可能的内容。

通常有一下三种:

Location: xxxx:yyyy/zzzz

Content-Type: xxxx/yyyy

Status: nnn xxxxxx

常用实例

1、实现重定向(状态302)

<?php
header("Location:http://www.baidu.com");
exit;

2、页面不存在(404页面)

<?php
header("HTTP/1.1 404 Not Found");
header("status:404 Not Found");

3、永久重定向

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location:http://www.baidu.com");

4、下载文件

 <?php
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');

5、设置文件类型

<?php
header('Content-Type: text/html; charset=utf-8'); header('Content-Type: text/plain'); header('Content-Type:image/jpeg'); header('Content-Type:application/zip'); header('Content-Type:application/pdf'); header('Content-Type:audio/mpeg'); header('Content-Type: application/x-shockwave-flash');

php header函数详解的更多相关文章

  1. php header 函数详解

    网页的缓存是由 HTTP消息头中的“Cache-control”来控制的,常见的取值有private.no-cache.max-age.must- revalidate等,默认为private.其作用 ...

  2. windows socket函数详解

    windows socket函数详解 近期一直用第三方库写网络编程,反倒是遗忘了网络编程最底层的知识.因而产生了整理Winsock函数库的想法.以下知识点均来源于MSDN,本人只做翻译工作.虽然很多前 ...

  3. PHP输出缓存ob系列函数详解

    PHP输出缓存ob系列函数详解 ob,输出缓冲区,是output buffering的简称,而不是output cache.ob用对了,是能对速度有一定的帮助,但是盲目的加上ob函数,只会增加CPU额 ...

  4. loadrunner 脚本优化-关联函数web_reg_save_param()函数详解

    脚本优化-关联函数web_reg_save_param()函数详解   by:授客 QQ:1033553122 Insert->New Step,打开Add Step对话框 选择函数web_re ...

  5. loadrunner 脚本开发- web_url函数详解

    脚本开发- web_url函数详解 by:授客 QQ:1033553122   加载指定url的web页面(GET请求) C语言函数 int web_url( const char *StepName ...

  6. malloc 与 free函数详解<转载>

    malloc和free函数详解   本文介绍malloc和free函数的内容. 在C中,对内存的管理是相当重要.下面开始介绍这两个函数: 一.malloc()和free()的基本概念以及基本用法: 1 ...

  7. NSSearchPathForDirectoriesInDomains函数详解

    NSSearchPathForDirectoriesInDomains函数详解     #import "NSString+FilePath.h" @implementation ...

  8. JavaScript正则表达式详解(二)JavaScript中正则表达式函数详解

    二.JavaScript中正则表达式函数详解(exec, test, match, replace, search, split) 1.使用正则表达式的方法去匹配查找字符串 1.1. exec方法详解 ...

  9. Linux C popen()函数详解

    表头文件 #include<stdio.h> 定义函数 FILE * popen( const char * command,const char * type); 函数说明 popen( ...

随机推荐

  1. WiFi破解

    BT5破解WPA2-PSK无线密码实践     笔者住处附近有无线信号,觉得可以试着破解一下,于是有了如下实践. 软硬件环境:Vmware Workstation 9,BT5 r3,reaver1.4 ...

  2. MFC下无法为空间添加变量解决

    许久不用MFC,今天在vs2008下用MFC写个小东西,结果在为控件添加变量的时候,居然无法成功——那个界面显示怪怪的,点击完成提示失败.    还好同事遇到过这个问题,给出链接http://hi.b ...

  3. iOS UILabel根据字符串长度自动适应宽度和高度

    //这个frame是初设的,没关系,后面还会重新设置其size.     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0, ...

  4. linux上配置网络/安装vsftp服务器

    1 准备用yum方式安装,小红帽linux原版不注册无法适用,只好安装centos系统 2 安装好centos系统注意事项: 硬盘得是IDE 配置好网络必须通,eth0的配置文件设置一下,联网启用 c ...

  5. ARM Linux 3.x的设备树(Device Tree)

    http://blog.csdn.net/21cnbao/article/details/8457546 宋宝华 Barry Song <21cnbao@gmail.com> 1.     ...

  6. who is the middle

    Description FJ is surveying his herd to find the most average cow. He wants to know how much milk th ...

  7. Round函数

    Round():函数返回一个数值,舍入到指定的长度或精度 eg: --1) ) ---->123.9990 ) ---->124.0000 --3为需要舍入的位数 --2) ) ----- ...

  8. 用JS制作简易的可切换的年历,类似于选项卡

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 30.0px Consolas; color: #2b7ec3 } p.p2 { margin: 0.0px ...

  9. 【堆】【kd-tree】bzoj2626 JZPFAR

    用堆记录答案.看看当前点是否比堆顶更优. #include<cstdio> #include<queue> #include<cstring> #include&l ...

  10. 新机自动创建yum库

    #!/bin/bash#for a newsystem to setup auto reposity YUM_DIR=/etc/yum.repos.dMOUNT_DIR=/mntDEV_DIR=&qu ...