<?php
header('HTTP/1.1 200 OK'); // ok 正常访问
header('HTTP/1.1 404 Not Found'); //通知浏览器 页面不存在
header('HTTP/1.1 301 Moved Permanently'); //设置地址被永久的重定向 301
header('Location: http://www.ithhc.cn/'); //跳转到一个新的地址
header('Refresh: 10; url=http://www.ithhc.cn/'); //延迟转向 也就是隔几秒跳转
header('X-Powered-By: PHP/6.0.0'); //修改 X-Powered-By信息
header('Content-language: en'); //文档语言
header('Content-Length: 1234'); //设置内容长度
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); //告诉浏览器最后一次修改时间
header('HTTP/1.1 304 Not Modified'); //告诉浏览器文档内容没有发生改变 ###内容类型###
header('Content-Type: text/html; charset=utf-8'); //网页编码
header('Content-Type: text/plain'); //纯文本格式
header('Content-Type: image/jpeg'); //JPG、JPEG
header('Content-Type: application/zip'); // ZIP文件
header('Content-Type: application/pdf'); // PDF文件
header('Content-Type: audio/mpeg'); // 音频文件
header('Content-type: text/css'); //css文件
header('Content-type: text/javascript'); //js文件
header('Content-type: application/json'); //json
header('Content-type: application/pdf'); //pdf
header('Content-type: text/xml'); //xml
header('Content-Type: application/x-shockw**e-flash'); //Flash动画 ###### ###声明一个下载的文件###
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="ITblog.zip"');
header('Content-Transfer-Encoding: binary');
readfile('test.zip');
###### ###对当前文档禁用缓存###
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
###### ###显示一个需要验证的登陆对话框###
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
###### ###声明一个需要下载的xls文件###
header('Content-Disposition: attachment; filename=ithhc.xlsx');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Length: '.filesize('./test.xls'));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile('./test.xls');
######
?>

  综上 Header 使用实例:Request >> PHP 返回json对象:

 * TODO 数据返回结构
* @param $code
* @param $msg
* @param $data
* @param $url
* @param $wait
* @return array
*/
function msg_array($code = 1,$msg="",$data=[],$url="",$wait= 3)
{
$result = [
'code' => $code,
'msg' => $msg,
'data' => $data,
'url' => $url,
'wait' => $wait,
];
return $result;
} header("Content-Type: application/json");
echo json_encode(msg_array(0,'logout success !'));exit;

  

标准响应字段

媒体类型 Content-Type : 常见的例子

  • application/javascript
  • application/json
  • application/x-www-form-urlencoded
  • application/xml
  • application/zip
  • application/pdf
  • application/sql
  • application/graphql
  • application/ld+json
  • application/msword (.doc)
  • application/vnd.openxmlformats-officedocument.wordprocessingml.document(.docx)
  • application/vnd.ms-excel (.xls)
  • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (.xlsx)
  • application/vnd.ms-powerpoint (.ppt)
  • application/vnd.openxmlformats-officedocument.presentationml.presentation (.pptx)
  • application/vnd.oasis.opendocument.text (.odt)
  • audio/mpeg
  • audio/ogg
  • multipart/form-data
  • text/css
  • text/html
  • text/xml
  • text/csv
  • text/plain
  • image/png
  • image/jpeg
  • image/gif

php Header 函数使用的更多相关文章

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

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

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

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

  3. PHP header函数使用大全

    PHP header函数大全 header('Content-Type: text/html; charset=utf-8'); header('Location: http://52php.cnbl ...

  4. PHP header函数的几大作用

    先看看官方文档的定义 (PHP 4, PHP 5, PHP 7) header - 发送原生 HTTP 头 void header ( string $string [, bool $replace ...

  5. PHP中header函数的用法及其注意重点是什么呢

    1.使用header函数进行跳转页面: header('Location:'.$url); 其中$url就是将要跳转的url了. 这种用法的注意事项有以下几点: •Location和":&q ...

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

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

  7. PHP header()函数

    对header函数,我用得最多的就是跳转页面和设置字符集,其他的功能用得比较少. 一.设置字符集 其实我们用的最多的在在html代码当中的<meta>标签里面设置字符集.格式如下: < ...

  8. PHP header() 函数详细说明(301、404等错误设置)

    原文来自:http://www.veryhuo.com/a/view/41466.html 如果您刚刚开始学习PHP,可能有许多函数需要研究,今天我们就来学习一下PHP Header()的使用方法,更 ...

  9. PHP header函数大全

    PHP header函数大全 header('Content-Type: text/html; charset=utf-8'); header('Location: http://www.php-no ...

  10. php header函数实例代码

    一个完美的演示PHP header()函数用法的完整代码. 其中介绍的refresh方法,比<META ……用起来更得心应手,应该是段不错的代码. <?php  /*** Function ...

随机推荐

  1. 纯CSS打造淘宝导航菜单栏

    店铺装修-PC端-基础页-首页-装修页面:编辑“菜单”模块-显示设置,粘贴如下CSS: /* 导航条背景色*/ .skin-box-bd .menu-list{background: none rep ...

  2. js无法获取.net设置的cookie

    使用CookieHelper帮助类: public class CookieHelper { #region 获取Cookie /// <summary> /// 获得Cookie的值 / ...

  3. asp.net core 今日所得

    ViewBag中文变量被编码.乱码. 解决方法: @Html.Raw(@ViewBag.XX) 在 Startup.cs 的 ConfigureServices() 方法中添加下面的一行代码: ser ...

  4. 【AO笔记】有关使用AO基于shp文件创建网络数据集的一个细节

    前些日子,和群友交流时提及shp文件创建单一网络数据集的创建问题. 由于项目需求,用shp文件创建网络合适,所以不得不去找一些古老的代码资料... 以前的研究中,创建网络数据集是根据IDatasetC ...

  5. ButterKnife的使用详解

    ButterKnife的使用详解 1,概述: ButterKnife则是注解中相对简单易懂的很不错的开源框架. ButterKnife是目前常用的一种依托Java注解机制实现辅助代码生成的框架:用到了 ...

  6. 使用GDB调试Android Native 层代码

    --------------步骤:0. adb root0. adb shell0. ps | grep browser1. gdbserver :5039 --attach pid2. adb fo ...

  7. VUE新版扫码下单必选分类设置FAQ

    使用场景:商家想要设置某些分类下的商品设置必选,否则不能下单.如某火锅店,商家想要设置汤底这个分类下的商品,顾客扫码下单的时候必须选择一份才能下单,此时 就可以使用这个功能 配置步骤和注意事项如下: ...

  8. js 倒计时跳转

    用js实现简单的倒计时结束页面跳转效果,主要用到setInterval()和clearInterval()方法,页面跳转使用window.location.href = " ".倒 ...

  9. Windows Server 2016-Windows安全日志ID汇总

    Windows常见安全事件日志ID汇总,供大家参考,希望可以帮到大家. ID 安全事件信息 1100 事件记录服务已关闭 1101 审计事件已被运输中断. 1102 审核日志已清除 1104 安全日志 ...

  10. SpringCloud微服务Zuul跨域问题

    目前项目结构是VUE做前端,后端采用微服务架构,在开发时前端需要跨域请求数据,通过ZuulFilter配置解决了简单跨域请求需要.但当需要在请求的header中增加token信息时,出现了请求失败的情 ...