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 ...
随机推荐
- socket,模拟服务器、客户端通信
服务器代码: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;u ...
- PHP接口APP接口
使用PHP来生成APP接口数据是非常简单的,如果你还不了解PHP没有关系,只需要看过PHP的基本语法,再看本示例就可以了. APP接口一般都是json格式(当然也有少数xml格式)遵循restful规 ...
- python3 Flask -day4 自定义url转换器
url传参可以限定参数的数据类型,例如:限定user_id数据类型为int @app.route('/user/<int:user_id>') def my_list(user_id): ...
- 利用IDisposable接口构建包含非托管资源对象
托管资源与非托管资源 在.net中,对象使用的资源分为两种:托管资源与非托管资源.托管资源由CLR进行管理,不需要开发人员去人工进行控制,.NET中托管资源主要指"对象在堆中的内存" ...
- LEDE 虚拟机安装
虽然我对路由器没什么兴趣,但是紧跟潮流还是有必要的,现在因为网络闭关锁国政策,很多人都想自己搭配一台私人的服务器,不想被商业公司左右数据安全.我感觉这个是一个商机,建议大家可以朝这个方向发展. 这里最 ...
- promise原理
简介 Promise 对象用于延迟(deferred) 计算和异步(asynchronous )计算.一个Promise对象代表着一个还未完成,但预期将来会完成的操作.Promise 对象是一个返 ...
- git常用命令总结--廖雪峰老师Git教程命令总结
学习了廖雪峰老师的Git教程之后的命令总结,重点关于git和远程仓库的东西. 如果没有学过,这是传送门 下面这个图很重要 一.git初始化本地仓库和配置 echo "想输入到文件的内容,一般 ...
- java获取机器IP地址常用方法
private String getHostIP(){ Enumeration<NetworkInterface> allNetInterfaces = null; String resu ...
- selenium-测试框架搭建(十三)
思路 分离业务代码和测试数据,提高代码可维护性,实现自动化,减少重复劳动. 一个测试框架大概由配置文件,测试数据,测试用例,相关文件(发送邮件等),测试日志,断言和测试报告等模块组成. 结构 以页面为 ...
- win10安装spacemacs
参考: https://www.cnblogs.com/e190/p/10404927.html https://blog.csdn.net/u011729865/article/details/54 ...
