PHP 使用header函数设置HTTP头的示例解析 表头

 更新时间:2013年06月17日 14:32:16   作者:  
本篇文章是对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语法实现 
// <meta http-equiv="refresh" content="10;http://www.example.org/ /> 

// 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; // or filemtime($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 中的批处理的实现

    PHP 中的批处理的实现

    PHP 中的批处理的实现...
    2007-06-06
  • PHP中返回引用类型的方法

    PHP中返回引用类型的方法

    这篇文章主要介绍了PHP中返回引用类型的方法,这是个比较容易混淆的概念,如果不是出于某些特殊的原因,建议还是不要使用,需要的朋友可以参考下
    2015-04-04
  • 理解php依赖注入和控制反转

    理解php依赖注入和控制反转

    这篇文章主要帮助大家理解php依赖注入和控制反转,感兴趣的小伙伴们可以参考一下
    2016-05-05
  • PHP连接MySQL数据库操作代码实例解析

    PHP连接MySQL数据库操作代码实例解析

    这篇文章主要介绍了PHP连接MySQL数据库操作代码实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-07-07
  • PHP strtotime函数详解

    PHP strtotime函数详解

    strtotime函数是一个很好的函数,灵活的运用它,会给你的工作带来不少方便.但PHP的手册中却对此函数的参数没作太多介绍,对些函数的其他介绍也非常少。
    2009-12-12
  • PHP实现多图上传(结合uploadify插件)思路分析

    PHP实现多图上传(结合uploadify插件)思路分析

    这篇文章主要介绍了PHP实现多图上传的方法,实例分析了php结合uploadify插件实现多图上传的具体步骤与相关操作技巧,需要的朋友可以参考下
    2016-11-11
  • 基于OpenCV的PHP图像人脸识别技术

    基于OpenCV的PHP图像人脸识别技术

    本文所介绍的技术不是原创,而是从一个叫Robert Eisele的德国人那里学习来的。他写了一个PHP扩展openCV,只封装了两个函数,叫face_detect和face_count。
    2009-10-10
  • php成功操作redis cluster集群的实例教程

    php成功操作redis cluster集群的实例教程

    这篇文章主要给大家介绍了关于php成功操作redis cluster集群的实例教程,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-01-01
  • php的urlencode()URL编码函数浅析

    php的urlencode()URL编码函数浅析

    URLEncode:是指针对网页url中的中文字符的一种编码转化方式,最常见的就是Baidu、Google等搜索引擎中输入中文查询时候,生成经过Encode过的网页URL。
    2011-08-08
  • .htaccess文件保护实例讲解

    .htaccess文件保护实例讲解

    .htaccess太强大了,但它本身会不会被破解掉呢,请问如何保护它?
    2011-02-02

最新评论