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

2015-01-24信息快讯网

本篇文章是对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';  
用Zend Studio+PHPnow+Zend Debugger搭建PHP服务器调试环境步骤
修改apache配置文件去除thinkphp url中的index.php
PHP获取php,mysql,apche的版本信息示例代码
windows下PHP_intl.dll正确配置方法(apache2.2+php5.3.5)
php中filter函数验证、过滤用户输入的数据
memcache命令启动参数中文解释
codeigniter框架批量插入数据
eaglephp使用微信api接口开发微信框架
php Calender(日历)代码分享
codeigniter使用技巧批量插入数据实例方法分享
php安装xdebug/php安装pear/phpunit详解步骤(图)
php实现memcache缓存示例讲解
php用header函数实现301跳转代码实例
php堆排序(heapsort)练习
php生成EAN_13标准条形码实例
php中autoload的用法总结
PHP中spl_autoload_register函数的用法总结
Php header()函数语法及使用代码
is_uploaded_file函数引发的不能上传文件问题
thinkphp中连接oracle时封装方法无法用的解决办法
thinkphp 多表 事务详解
CentOS 6.2使用yum安装LAMP以及phpMyadmin详解
PHP中array_merge和array相加的区别分析
php之Memcache学习笔记
探讨:如何通过stats命令分析Memcached的内部状态
PHP操作Memcache实例介绍
深入Memcache的Session数据的多服务器共享详解
eAccelerator的安装与使用详解
探讨Hessian在PHP中的使用分析
基于PHP输出缓存(output_buffering)的深入理解
php缓冲 output_buffering的使用详解
深入PHP autoload机制的详解
探讨PHP使用eAccelerator的API开发详解
深入for,while,foreach遍历时间比较的详解
探讨php中header的用法详解
深入eAccelerator与memcached的区别详解
基于header的一些常用指令详解
PHP autoload与spl_autoload自动加载机制的深入理解
©2014-2024 dbsqp.com