分享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 09 PHP
php数组函数序列之next() - 移动数组内部指针到下一个元素的位置,并返回该元素值
Oct 31 PHP
php数组查找函数in_array()、array_search()、array_key_exists()使用实例
Apr 29 PHP
php编写的一个E-mail验证类
Mar 25 PHP
php支持中文字符串分割的函数
May 28 PHP
php生成二维码
Aug 10 PHP
php实现smarty模板无限极分类的方法
Dec 07 PHP
thinkphp框架实现删除和批量删除
Jun 29 PHP
PHP中字符与字节的区别及字符串与字节转换示例
Oct 15 PHP
thinkPHP模板中for循环与switch语句用法示例
Nov 30 PHP
基于thinkPHP类的插入数据库操作功能示例
Jan 06 PHP
解决laravel 表单提交-POST 异常的问题
Oct 15 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
第六节--访问属性和方法
2006/11/16 PHP
Dedecms V3.1 生成HTML速度的优化办法
2007/03/18 PHP
PHP简单装饰器模式实现与用法示例
2017/06/22 PHP
PHP+JS实现的实时搜索提示功能
2018/03/13 PHP
PHP实现数组转JSon和JSon转数组的方法示例
2018/06/14 PHP
详解PHP的抽象类和抽象方法以及接口总结
2019/03/15 PHP
js 未结束的字符串常量错误解决方法
2010/06/13 Javascript
jQuery获取样式中的背景颜色属性值/颜色值
2012/12/17 Javascript
jquery实现盒子下拉效果示例代码
2013/09/12 Javascript
jquery实现checkbox全选全不选的简单实例
2013/12/31 Javascript
form.submit()不能提交表单的错误原因及解决方法
2014/10/13 Javascript
JavaScript严格模式详解
2015/11/18 Javascript
js实现文字超出部分用省略号代替实例代码
2016/09/01 Javascript
Ajax的概述与实现过程
2016/11/18 Javascript
手把手教你vue-cli单页到多页应用的方法
2018/05/31 Javascript
微信小程序实现下拉菜单切换效果
2020/03/30 Javascript
如何在Angular8.0下使用ngx-translate进行国际化配置
2019/07/24 Javascript
使用axios发送post请求,将JSON数据改为form类型的示例
2019/10/31 Javascript
jquery实现直播视频弹幕效果
2020/02/25 jQuery
jQuery实现雪花飘落效果
2020/08/02 jQuery
python中xrange用法分析
2015/04/15 Python
使用Python设置tmpfs来加速项目的教程
2015/04/17 Python
Python入门之三角函数全解【收藏】
2017/11/08 Python
python实现机器人行走效果
2018/01/29 Python
Pycharm 操作Django Model的简单运用方法
2018/05/23 Python
python版本单链表实现代码
2018/09/28 Python
Python实现将多个空格换为一个空格.md的方法
2018/12/20 Python
Pytorch在NLP中的简单应用详解
2020/01/08 Python
计算pytorch标准化(Normalize)所需要数据集的均值和方差实例
2020/01/15 Python
幼儿教师培训感言
2014/03/08 职场文书
专题民主生活会对照检查材料思想汇报
2014/09/29 职场文书
2016年大学生实习单位评语
2015/12/01 职场文书
党风廉政承诺书2016
2016/03/25 职场文书
2016年“5.12”国际护士节活动总结
2016/04/06 职场文书
2019运动会广播加油稿汇总
2019/08/21 职场文书
 分享一个Python 遇到数据库超好用的模块
2022/04/06 Python