分享PHP header函数使用教程


Posted in PHP onSeptember 05, 2013
<?php 
// fix 404 pages: 
header('HTTP/1.1 200 OK'); 
// set 404 header: 
header('HTTP/1.1 404 Not Found'); 
// set Moved Permanently header (good for redrictions) 
// use with location header 
header('HTTP/1.1 301 Moved Permanently'); 
// redirect to a new location: 
header('Location: http://www.example.org/'); 
// redrict with delay: 
header('Refresh: 10; url=http://www.example.org/'); 
print 'You will be redirected in 10 seconds'; 
// you could also use the HTML syntax:// <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'); 
// content language (en = English) 
header('Content-language: en'); 
// last modified (good for caching) 
$time = time() ? 60; // or filemtime($fn), etc 
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); 
// header for telling the browser that the content 
// did not get changed 
header('HTTP/1.1 304 Not Modified'); 
// set content length (good for caching): 
header('Content-Length: 1234'); 
// Headers for an download: 
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'); 
// Disable caching of the current document: 
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 pastheader('Pragma: no-cache'); 
// set content type: 
header('Content-Type: text/html; charset=iso-8859-1'); 
header('Content-Type: text/html; charset=utf-8'); 
header('Content-Type: text/plain'); 
// plain text file 
header('Content-Type: image/jpeg'); 
// JPG picture 
header('Content-Type: application/zip'); 
// ZIP file 
header('Content-Type: application/pdf'); 
// PDF file 
header('Content-Type: audio/mpeg'); 
// Audio MPEG (MP3,…) file 
header('Content-Type: application/x-shockwave-flash'); 
// Flash animation// show sign in box 
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提取视频网站页面中的FLASH地址的代码
Apr 17 PHP
php数组函数序列之array_intersect() 返回两个或多个数组的交集数组
Nov 10 PHP
PHP中鲜为人知的10个函数
Feb 28 PHP
php采用file_get_contents代替使用curl实例
Nov 07 PHP
Yii不依赖Model的表单生成器用法实例
Dec 04 PHP
php使用Jpgraph绘制复杂X-Y坐标图的方法
Jun 10 PHP
WordPress用户登录框密码的隐藏与部分显示技巧
Dec 31 PHP
PHP模板引擎Smarty内建函数详解
Apr 11 PHP
PHP is_array() 检测变量是否是数组的实现方法
Jun 13 PHP
PHP实现将几张照片拼接到一起的合成图片功能【便于整体打印输出】
Nov 14 PHP
在PHP中输出JS语句以及乱码问题的解决方案
Feb 13 PHP
浅谈laravel数据库查询返回的数据形式
Oct 21 PHP
php增删改查示例自己写的demo
Sep 04 #PHP
php使用异或实现的加密解密实例
Sep 04 #PHP
PHP中数组定义的几种方法
Sep 01 #PHP
对淘宝URL中ID提取的PHP代码
Sep 01 #PHP
怎么在Windows系统中搭建php环境
Aug 31 #PHP
深入解析php中的foreach函数
Aug 31 #PHP
如何使用php输出时间格式
Aug 31 #PHP
You might like
PHP制作图型计数器的例子
2006/10/09 PHP
php警告Creating default object from empty value 问题的解决方法
2014/04/02 PHP
php+jquery+html实现点击不刷新加载更多的实例代码
2016/08/12 PHP
jquery键盘事件使用介绍
2011/11/01 Javascript
JS小游戏之极速快跑源码详解
2014/09/25 Javascript
javascript中hasOwnProperty() 方法使用指南
2015/03/09 Javascript
jQuery层动画定位滑动效果的方法
2015/04/30 Javascript
Bootstrap每天必学之进度条
2015/11/30 Javascript
jQuery实现控制文字内容溢出用省略号(…)表示的方法
2016/02/26 Javascript
JavaScript常用函数工具集:lao-utils
2016/03/01 Javascript
Vue.js实现移动端短信验证码功能
2017/03/29 Javascript
AngularJS实现图片上传和预览功能的方法分析
2017/11/08 Javascript
vue.js简单配置axios的方法详解
2017/12/13 Javascript
webpack分离css单独打包的方法
2018/06/12 Javascript
Vue.directive使用注意(小结)
2018/08/31 Javascript
vue项目创建并引入饿了么elementUI组件的步骤
2019/04/11 Javascript
基于vue hash模式微信分享#号的解决
2020/09/07 Javascript
原生JavaScript实现随机点名表
2021/01/14 Javascript
[02:23]2014DOTA2国际邀请赛中国战队回顾
2014/08/01 DOTA
[48:52]DOTA2上海特级锦标赛A组小组赛#2 Secret VS CDEC第一局
2016/02/25 DOTA
Python处理XML格式数据的方法详解
2017/03/21 Python
python实现微信跳一跳辅助工具步骤详解
2018/01/04 Python
基于python内置函数与匿名函数详解
2018/01/09 Python
使用python脚本实现查询火车票工具
2018/07/19 Python
在Python 中同一个类两个函数间变量的调用方法
2019/01/31 Python
详解用pyecharts Geo实现动态数据热力图城市找不到问题解决
2019/06/26 Python
PyTorch 解决Dataset和Dataloader遇到的问题
2020/01/08 Python
Transpose 数组行列转置的限制方式
2020/02/11 Python
python有序查找算法 二分法实例解析
2020/02/18 Python
BookOutlet加拿大:在网上书店购买廉价折扣图书和小说
2018/10/05 全球购物
就业协议书怎么填
2014/09/15 职场文书
继续教育个人总结
2015/03/03 职场文书
小学语文继续教育研修日志
2015/11/13 职场文书
小学英语听课心得体会
2016/01/14 职场文书
mysql优化
2021/04/06 MySQL
「Manga Time Kirara MAX」2022年5月号封面公开
2022/03/21 日漫