php Header 函数使用
<?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/javascriptapplication/jsonapplication/x-www-form-urlencodedapplication/xmlapplication/zipapplication/pdfapplication/sqlapplication/graphqlapplication/ld+jsonapplication/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/mpegaudio/oggmultipart/form-datatext/csstext/htmltext/xmltext/csvtext/plainimage/pngimage/jpegimage/gif
php Header 函数使用的更多相关文章
- PHP header函数设置http报文头(设置头部域)
PHP HTTP 简介: HTTP 函数允许您在其他输出被发送之前,对由 Web 服务器发送到浏览器的信息进行操作. PHP 5 HTTP 函数:header() 向客户端发送原始的 HTTP ...
- PHP中的header()函数作用
PHP 中 header()函数的作用是给客户端发送头信息. 什么是头信息?这里只作简单解释,详细的自己看http协议.在 HTTP协议中,服务器端的回答(response)内容包括两部分:头信息(h ...
- PHP header函数使用大全
PHP header函数大全 header('Content-Type: text/html; charset=utf-8'); header('Location: http://52php.cnbl ...
- PHP header函数的几大作用
先看看官方文档的定义 (PHP 4, PHP 5, PHP 7) header - 发送原生 HTTP 头 void header ( string $string [, bool $replace ...
- PHP中header函数的用法及其注意重点是什么呢
1.使用header函数进行跳转页面: header('Location:'.$url); 其中$url就是将要跳转的url了. 这种用法的注意事项有以下几点: •Location和":&q ...
- php header()函数设置页面Cache缓存
header()函数在php的使用很大,下面我来介绍利用它实现页面缓存的一些方法,但使用header前必须注意,在它之前不能任何输出,包括空格. 手册上,我们对于cache都是写着如何设置,以便让代码 ...
- PHP header()函数
对header函数,我用得最多的就是跳转页面和设置字符集,其他的功能用得比较少. 一.设置字符集 其实我们用的最多的在在html代码当中的<meta>标签里面设置字符集.格式如下: < ...
- PHP header() 函数详细说明(301、404等错误设置)
原文来自:http://www.veryhuo.com/a/view/41466.html 如果您刚刚开始学习PHP,可能有许多函数需要研究,今天我们就来学习一下PHP Header()的使用方法,更 ...
- PHP header函数大全
PHP header函数大全 header('Content-Type: text/html; charset=utf-8'); header('Location: http://www.php-no ...
- php header函数实例代码
一个完美的演示PHP header()函数用法的完整代码. 其中介绍的refresh方法,比<META ……用起来更得心应手,应该是段不错的代码. <?php /*** Function ...
随机推荐
- 事件Event一
事件(Event)例如:最近的视觉中国'黑洞事件'.我们大多数人(订阅者)是通过XX平台(发布者)得知的这一消息,然后订阅者A出售视觉中国的股票(触发的方法),订阅者B买入视觉中国的股票. using ...
- arcgis api 3.x for js 之 echarts 开源 js 库实现地图统计图分析(附源码下载)
前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...
- jQuery事件绑定,解绑,触发
事件绑定 1.bind(type,[data],fn) --type: 含有一个或多个事件类型的字符串,由空格分隔多个事件.比如"click"或"submit" ...
- 碰到了通过Movie显示gif图片,有部分图片的duration为0导致gif只显示第一帧
解决办法,改为使用android-gif-drawable.jar来显示gif图片(需要配合com.android.support:support-v4:18.0.0使用) GifImageView ...
- USB_ModeSwitch for Android 7
USB_ModeSwitch官网: USB_ModeSwitch - Handling Mode-Switching USB Devices on Linux USB_ModeSwitch for A ...
- webstorm2018.1 汉化
https://github.com/pingfangx/TranslatorX 这个百度云 选择webstorm 选择勾选的文件 选择你下载webstorm 的版本 我下载的是2018.1的 之后等 ...
- 微软与开源干货对比篇_PHP和 ASP.NET在 Session实现和管理机制上差异
微软与开源干货对比篇_PHP和 ASP.NET在 Session实现和管理机制上差异 前言:由于开发人员要靠工具吃饭,可能和开发工具.语言.环境呆的时间比和老婆孩子亲人在一起的时间还多,所以每个人或多 ...
- python中os模块和sys模块的常见用法
OS模块的常见用法 os.remove() 删除文件 os.rename() 重命名文件 os.walk() 生成目录树下的所有文件名 os.chdir() 改变目录 os.mkd ...
- Wsus Content内容误删处理
问题:在wsus content文件夹下误删除文件,需要重新下载文件解决方法:打开cmdcd C:\Program Files\Update Services\Tools\.\wsusutil.exe ...
- Kafka Tuning Recommendations
Kafka Brokers per Server Recommend 1 Kafka broker per server- Kafka not only disk-intensive but can ...
