分享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
Jun 29 PHP
IP138 IP地址查询小偷实现代码
Feb 15 PHP
谷歌音乐搜索栏的提示功能php修正代码
May 09 PHP
php中mysql模块部分功能的简单封装
Sep 30 PHP
PHP函数篇之掌握ord()与chr()函数应用
Dec 05 PHP
解析php中获取url与物理路径的总结
Jun 21 PHP
PHP实现抓取迅雷VIP账号的方法
Jul 30 PHP
PHP mysql事务问题实例分析
Jan 18 PHP
yii2.0实现pathinfo的形式访问的配置方法
Apr 06 PHP
thinkPHP3.1验证码的简单实现方法
Apr 22 PHP
适合PHP初学者阅读的4本经典书籍
Sep 23 PHP
PHP的PDO连接讲解
Jan 24 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生成随机颜色的方法
2014/11/13 PHP
十个PHP高级应用技巧果断收藏
2015/09/25 PHP
php使用include 和require引入文件的区别
2017/02/16 PHP
几个比较实用的JavaScript 测试及效验工具
2010/04/18 Javascript
通过jquery-ui中的sortable来实现拖拽排序的简单实例
2016/05/24 Javascript
JavaScript如何实现跨域请求
2016/08/05 Javascript
打造自己的jQuery插件入门教程
2016/09/23 Javascript
jQuery progressbar通过Ajax请求实现后台进度实时功能
2016/10/11 Javascript
JavaScript数据结构之单链表和循环链表
2017/11/28 Javascript
动态加载、移除js/css文件的示例代码
2018/03/20 Javascript
解决vuecli3.0热更新失效的问题
2018/09/19 Javascript
vue.js实现的幻灯片功能示例
2019/01/18 Javascript
JS学习笔记之贪吃蛇小游戏demo实例详解
2019/05/29 Javascript
JS代码优化的8点建议
2020/02/04 Javascript
使用python获取CPU和内存信息的思路与实现(linux系统)
2014/01/03 Python
python解析html开发库pyquery使用方法
2014/02/07 Python
python通过yield实现数组全排列的方法
2015/03/18 Python
Python实现的文本简单可逆加密算法示例
2017/05/18 Python
python中的二维列表实例详解
2018/06/19 Python
python使用response.read()接收json数据的实例
2018/12/19 Python
python 控制Asterisk AMI接口外呼电话的例子
2019/08/08 Python
Python 实现一行输入多个数字(用空格隔开)
2020/04/29 Python
最新PyCharm 2020.2.3永久激活码(亲测有效)
2020/11/26 Python
Vans英国官方网站:美国南加州的原创极限运动潮牌
2017/01/20 全球购物
匈牙利最大的健身制造商和销售商:inSPORTline
2018/10/30 全球购物
Kendra Scott官网:美国领先的时尚配饰品牌
2020/10/22 全球购物
大学生学习党课思想汇报
2014/01/03 职场文书
竞聘书怎么写,如何写?
2014/03/31 职场文书
初中英语课后反思
2014/04/25 职场文书
绿色环保口号
2014/06/12 职场文书
自我管理的活动方案
2014/08/25 职场文书
使用pandas或numpy处理数据中的空值(np.isnan()/pd.isnull())
2021/05/14 Python
利用Python判断你的密码难度等级
2021/06/02 Python
Python实现单例模式的5种方法
2021/06/15 Python
深入理解 Golang 的字符串
2022/05/04 Golang
MySQL批量更新不同表中的数据
2022/05/11 MySQL