分享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 相关文章推荐
phpmyadmin显示utf8_general_ci中文乱码的问题终级篇
Apr 08 PHP
PHP curl 获取响应的状态码的方法
Jan 13 PHP
php面向对象中的魔术方法中文说明
Mar 04 PHP
php url路由入门实例
Apr 23 PHP
php实现的简单日志写入函数
Mar 31 PHP
php判断表是否存在的方法
Jun 18 PHP
php实现比较全的数据库操作类
Jun 18 PHP
PHP正则表达式匹配替换与分割功能实例浅析
Feb 04 PHP
php获取ajax的headers方法与内容实例
Dec 27 PHP
Laravel框架中缓存的使用方法分析
Sep 06 PHP
laravel框架中表单请求类型和CSRF防护实例分析
Nov 23 PHP
gearman中任务的优先级和返回状态实例分析
Feb 27 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 接口类与抽象类的实际作用
2009/11/26 PHP
web server使用php生成web页面的三种方法总结
2013/10/28 PHP
摘自织梦CMS中的图片处理类
2015/08/08 PHP
PHP载入图像imagecreatefrom_gif_jpeg_png系列函数用法分析
2016/11/14 PHP
createElement与createDocumentFragment的点点区别小结
2011/12/19 Javascript
JQuery插件Style定制化方法的分析与比较
2012/05/03 Javascript
Javacript实现颜色梯度变化和渐变的效果代码
2013/05/31 Javascript
js中typeof的用法汇总
2013/12/12 Javascript
jQuery中unwrap()方法用法实例
2015/01/16 Javascript
javascript转换日期字符串为Date日期对象的方法
2015/02/13 Javascript
原创jQuery弹出层插件分享
2015/04/02 Javascript
jQuery简单实现页面元素置顶时悬浮效果示例
2016/08/01 Javascript
js自调用匿名函数的三种写法(推荐)
2016/08/19 Javascript
Node.js数据库操作之查询MySQL数据库(二)
2017/03/04 Javascript
AngularJS实现的简单拖拽功能示例
2018/01/02 Javascript
动态内存分配导致影响Javascript性能的问题
2018/12/18 Javascript
在Node.js中将SVG图像转换为PNG,JPEG,TIFF,WEBP和HEIF格式的方法
2019/08/22 Javascript
微信小程序 textarea 层级过高问题简单解决方案
2019/10/14 Javascript
vue 实现移动端键盘搜索事件监听
2019/11/06 Javascript
解决vue v-for src 图片路径问题 404
2019/11/12 Javascript
微信小程序实现上传多个文件 超过10个
2020/03/30 Javascript
python dict remove数组删除(del,pop)
2013/03/24 Python
通过数据库向Django模型添加字段的示例
2015/07/21 Python
Python读取二进制文件代码方法解析
2020/06/22 Python
HTML5实现页面切换激活的PageVisibility API使用初探
2016/05/13 HTML / CSS
html5唤醒APP小记
2019/03/27 HTML / CSS
canvas 基础之图像处理的使用
2020/04/10 HTML / CSS
高品质和独特的产品世界:Creations and Collections
2018/01/07 全球购物
医学检验专业个人求职信范文
2013/12/04 职场文书
竞聘上岗演讲
2014/05/19 职场文书
社区精神文明建设汇报材料
2014/08/17 职场文书
个人批评与自我批评材料
2014/10/17 职场文书
2015年小学生自我评价范文
2015/03/03 职场文书
电力企业职工培训心得体会
2016/01/11 职场文书
JS + HTML 罗盘式时钟的实现
2021/05/21 Javascript
Python利用FlashText算法实现替换字符串
2022/03/31 Python