分享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中创建并处理图象
Oct 09 PHP
PHP+AJAX实现无刷新注册(带用户名实时检测)
Jan 02 PHP
PHP 和 MySQL 开发的 8 个技巧
Jan 02 PHP
PHP实现邮件群发的源码
Jun 18 PHP
解析smarty 截取字符串函数 truncate的用法介绍
Jun 20 PHP
解析isset与is_null的区别
Aug 09 PHP
PHP 之 写时复制介绍(Copy On Write)
May 13 PHP
php可扩展的验证类实例(可对邮件、手机号、URL等验证)
Jul 09 PHP
全新Mac配置PHP开发环境教程
Feb 03 PHP
PHP使用PHPExcel删除Excel单元格指定列的方法
Jul 06 PHP
Laravel框架实现修改登录和注册接口数据返回格式的方法
Aug 17 PHP
PHP预定义超全局数组变量小结
Aug 20 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
Apache下禁止php文件被直接访问的解决方案
2013/04/25 PHP
基于php缓存的详解
2013/05/15 PHP
php获取根域名方法汇总
2014/10/28 PHP
php文件缓存类汇总
2014/11/21 PHP
PHP基于面向对象实现的留言本功能实例
2018/04/04 PHP
Laravel框架中集成MongoDB和使用详解
2019/10/17 PHP
JS+flash实现chrome和ie浏览器下同时可以复制粘贴
2013/09/22 Javascript
js和html5实现手机端刮刮卡抽奖效果完美兼容android/IOS
2013/11/18 Javascript
jquery实现保存已选用户
2014/07/21 Javascript
jQuery中[attribute*=value]选择器用法实例
2014/12/31 Javascript
js实现的二级横向菜单条实例
2015/08/22 Javascript
JavaScript获取图片像素颜色并转换为box-shadow显示
2016/03/11 Javascript
jQuery toggle 代替方法
2016/03/22 Javascript
卸载安装Node.js与npm过程详解
2016/08/15 Javascript
jQuery插件ajaxFileUpload使用实例解析
2016/10/19 Javascript
使用 jQuery.ajax 上传带文件的表单遇到的问题
2016/10/31 Javascript
angularjs下ng-repeat点击元素改变样式的实现方法
2018/09/12 Javascript
微信小程序之onLaunch与onload异步问题详解
2019/03/28 Javascript
js图片查看器插件用法示例
2019/06/22 Javascript
JavaScript判断浏览器运行环境的详细方法
2019/06/30 Javascript
jQuery实现鼠标放置名字上显示详细内容气泡提示框效果的方法分析
2020/04/04 jQuery
[02:45]DOTA2英雄基础教程 伐木机
2013/12/23 DOTA
[03:03]2014DOTA2国际邀请赛 EG战队专访
2014/07/12 DOTA
详解python-图像处理(映射变换)
2019/03/22 Python
新手常见Python错误及异常解决处理方案
2020/06/18 Python
波兰品牌内衣及泳装网上商店:Astratex.pl
2017/02/03 全球购物
一百多行代码实现react拖拽hooks
2021/03/23 Javascript
高中政治教学反思
2014/01/18 职场文书
4s店销售经理岗位职责
2014/07/19 职场文书
2015秋季新学期开学寄语
2015/05/28 职场文书
幼儿园秋季开学通知
2015/07/16 职场文书
2016大学生就业指导课心得体会
2016/01/15 职场文书
2017公司年会主持人开幕词
2016/03/04 职场文书
2016年党员岗位承诺书
2016/03/24 职场文书
Python排序算法之插入排序及其优化方案详解
2021/06/11 Python
javascript数组includes、reduce的基本使用
2021/07/02 Javascript