PHP常用 header函数设置HTTP头部示例
PHP常用 header函数设置HTTP头部示例
定义编码
header( 'Content-Type:text/html;charset=utf-8 ');
Atom
header(‘Content-type: application/atom+xml’);
CSS
header(‘Content-type: text/css’);
Javascript
header(‘Content-type: text/javascript’);
JPEG Image
header(‘Content-type: image/jpeg’);
JSON
header(‘Content-type: application/json’);
PDF
header(‘Content-type: application/pdf’);
RSS
header(‘Content-Type: application/rss+xml; charset=ISO-8859-1’);
Text (Plain)
header(‘Content-type: text/plain’);
XML
header(‘Content-type: text/xml’);
OK
header(‘HTTP/1.1 200 OK’);
设置一个404头
header(‘HTTP/1.1 404 Not Found’);
设置地址被永久的重定向
header(‘HTTP/1.1 301 Moved Permanently’);
转到一个新地址
header(‘Location: http://www.example.org/’);
文件延迟转向
header(‘Refresh: 10; url=http://www.example.org/’);
print ‘You will be redirected in 10 seconds’;
当然,也可以使用html语法实现
override X-Powered-By: PHP:
header(‘X-Powered-By: PHP/4.4.0’);
header(‘X-Powered-By: Brain/0.6b’);
文档语言
header(‘Content-language: en’);
告诉浏览器最后一次修改时间
time=time()−60;//orfilemtime(time = time() - 60; // or filemtime(time=time()−60;//orfilemtime(fn), etc
header(‘Last-Modified: ‘.gmdate(‘D, d M Y H:i:s’, $time).’ GMT’);
告诉浏览器文档内容没有发生改变
header(‘HTTP/1.1 304 Not Modified’);
设置内容长度
header(‘Content-Length: 1234’);
设置为一个下载类型
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’);
对当前文档禁用缓存
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 past
header(‘Pragma: no-cache’);
设置内容类型
header(‘Content-Type: text/html; charset=iso-8859-1’);
header(‘Content-Type: text/html; charset=utf-8’);
header(‘Content-Type: text/plain’); //纯文本格式
header(‘Content-Type: image/jpeg’); //JPG***
header(‘Content-Type: application/zip’); // ZIP文件
header(‘Content-Type: application/pdf’); // PDF文件
header(‘Content-Type: audio/mpeg’); // 音频文件
header(‘Content-Type: application/x-shockw**e-flash’); //Flash动画
显示登陆对话框
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’;
PHP常用 header函数设置HTTP头部示例相关推荐
- php odbc 结果集处理,php常用ODBC函数集的简单示例
这篇文章主要为大家详细介绍了php常用ODBC函数集的简单示例,具有一定的参考价值,可以用来参考一下. 感兴趣的小伙伴,下面一起跟随512笔记的小玲来看看吧! ODBC连接类函数 odbc_conne ...
- PHP 使用header函数设置HTTP头的示例方法 表头(转)
//定义编码 header( 'Content-Type:text/html;charset=utf-8 '); //Atom header('Content-type: application/at ...
- php头代码,PHP常用header头定义代码示例汇总
在php的开发中,我们常常需要使用到header函数头来进行做标记 header() 函数向客户端发送原始的 HTTP 报头. 常用header设置列表如下: header('HTTP/1.1 200 ...
- xml相关php函数,PHP利用xml常用函数的详细集合示例
这篇文章主要为大家详细介绍了PHP利用xml常用函数的详细集合示例,具有一定的参考价值,可以用来参考一下. 感兴趣的小伙伴,下面一起跟随512笔记的小玲来看看吧! 1.DOM 函数 a.DOMDocu ...
- php 判断函数禁用,php禁用函数设置及查看方法的介绍(附示例)
本篇文章给大家带来的内容是关于php禁用函数设置及查看方法的介绍(附示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 这篇文章主要介绍了php禁用函数设置及查看方法,结合实例形式 ...
- C语言常用函数详细总结附示例(快速掌握)
目录 一.简介 二.常用函数 2.1 strncpy 2.2 strcmp: 2.3 memset 2.4 strlen 2.5 memcpy 2.6 ioremap 2.7 mmap 三.其他c语言 ...
- 跨域 · 后台设置:头部header(服务器端添加属性、属性值,浏览器端获取属性及其值) - 数据篇
跨域 · 后台设置:头部header自定义属性 (服务器端添加属性.属性值,浏览器端获取属性及其值) headers 服务端配置 # For more information on configura ...
- php header 转向,php使用header函数的http头设置大全(包含301转向及404状态)
最近做B2B系统,为给每个会员自动赠送的二级域名店铺做一些SEO优化,要用到header函数来设置域名的301转向以及404状态,以下是从网上找的header函数的http头设置大全,收藏到我的博客中 ...
- php header函数的详解,php header函数的详解_PHP教程
header函数在php中是发前一些头部信息的,如果我们可以直接使用它来做301跳转等,下面我来总结关于header函数用法与一些常用见问题解决方法. 发送一个原始 HTTP 标头[Http Head ...
最新文章
- 移柯L620模组使用MQTT协议连接移动OneNet云平台(NB-IoT专栏—进阶篇3)
- 神经网络 | 基于脉冲耦合神经网络(PCNN)的图像特征提取(Matlab源代码)
- PHP的替换strstr strtr str_replace substr_replace
- CodeForces - 1316D Nash Matrix(构造+dfs)
- 2018年湘潭大学程序设计竞赛 G又见斐波那契
- Powershell创建数组
- 微软推出新逆天开源语言,告别 for 循环,提高开发效率!
- 怎么在Android布局里面写下拉框,Android CoordinatorLayout(六) 加入下拉功能
- extremecomponents-1.0.1.jar 的使用小例子
- Angular端口4200被占用后如何处理
- 神经网络算法实例应用题,神经网络算法实例应用
- 论文解读:《EMDLP:RNA甲基化位点预测的合奏多尺度深度学习模型》
- Android版微信跳一跳小游戏如何利用技术手段达到高分!
- viewModel生命周期
- Solr评分整理汇总:深入理解Lucene默认打分算法以及常用的三种评分方法
- 拼多多API接口介绍
- Mac pro 连上wifi 5G提示无ip地址
- JavaScript基础(4)_强制类型转换
- 台式计算机风扇为什么光散热,台式机箱风扇为什么要使用静音风扇
- 数字抽奖小程序_如何利用小程序玩转抽奖活动?