分享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获取url字符串截取路径的文件名和扩展名的函数
Jan 22 PHP
领悟php接口中interface存在的意义
Jun 27 PHP
浅析php中抽象类和接口的概念以及区别
Jun 27 PHP
PHP网页游戏学习之Xnova(ogame)源码解读(四)
Jun 23 PHP
php短信接口代码
May 13 PHP
Ubuntu 16.04下安装PHP 7过程详解
Mar 28 PHP
利用PHP获取汉字首字母并且分组排序详解
Oct 22 PHP
PHP实现基于栈的后缀表达式求值功能
Nov 10 PHP
PDO::lastInsertId讲解
Jan 29 PHP
php解决约瑟夫环算法实例分析
Sep 30 PHP
laravel框架的安装与路由实例分析
Oct 11 PHP
CI框架简单分页类用法示例
Jun 06 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
解析百度搜索结果link?url=参数分析 (全)
2012/10/09 PHP
了解PHP的返回引用和局部静态变量
2015/06/04 PHP
JavaScript 高级语法介绍
2009/06/15 Javascript
jquery监控数据是否变化(修正版)
2011/04/12 Javascript
window.requestAnimationFrame是什么意思,怎么用
2013/01/13 Javascript
深入浅析JavaScript系列(13):This? Yes,this!
2016/01/05 Javascript
使用jquery/js获取iframe父子级、同级获取元素的方法
2016/08/05 Javascript
jQuery使用unlock.js插件实现滑动解锁
2017/04/04 jQuery
详解Vue + Vuex 如何使用 vm.$nextTick
2017/11/20 Javascript
基于vue.js中事件修饰符.self的用法(详解)
2018/02/23 Javascript
p5.js实现斐波那契螺旋的示例代码
2018/03/22 Javascript
详解使用vue-admin-template的优化历程
2018/05/20 Javascript
在react中使用vuex的示例代码
2018/07/30 Javascript
vue v-on:click传递动态参数的步骤
2020/09/11 Javascript
[03:08]TI9战队档案 - Vici Gaming
2019/08/20 DOTA
Python使用PyCrypto实现AES加密功能示例
2017/05/22 Python
详解Python nose单元测试框架的安装与使用
2017/12/20 Python
django rest framework 数据的查找、过滤、排序的示例
2018/06/25 Python
python中csv文件的若干读写方法小结
2018/07/04 Python
python按时间排序目录下的文件实现方法
2018/10/17 Python
python把ipynb文件转换成pdf文件过程详解
2019/07/09 Python
python读取.mat文件的数据及实例代码
2019/07/12 Python
Python configparser模块应用过程解析
2020/08/14 Python
请编程遍历页面上所有 TextBox 控件并给它赋值为 string.Empty
2015/12/03 面试题
95%的面试官都会问到的50道Java线程题,附答案
2012/08/03 面试题
英语专业毕业个人求职自荐信
2013/09/21 职场文书
个人求职信范文分享
2013/12/13 职场文书
幼儿园大班毕业教师寄语
2014/04/03 职场文书
优秀大专毕业生求职信
2014/08/04 职场文书
2014旅游局党组书记党建工作汇报材料
2014/11/02 职场文书
2014年内勤工作总结
2014/11/24 职场文书
因个人原因离职的辞职信范文
2015/05/12 职场文书
2015年体育教学工作总结
2015/05/20 职场文书
学校就业保障协议书
2019/06/24 职场文书
如何写一份成功的商业计划书
2019/06/25 职场文书
nginx 配置指令之location使用详解
2022/05/25 Servers