php header函数实例代码
其中介绍的refresh方法,比<META ……用起来更得心应手,应该是段不错的代码。
/*** Function: PHP header() examples (PHP)
** Desc: Some examples on how to use the header() function of PHPYou find a detailed tutorial at expertsrt.com (English) or at ffm.junetz.de (German).These is also a good help about caching at web-caching.com.
** Example: see below. <br/><br/><b>Tip:</b> You can use these sites to check your headers: <a href="http://web-sniffer.net/">web-sniffer.net</a>, <a href="http://www.jbxue.com/web/headers.html">jbxue.com</a> or <a href="http://www.jbxue.com/projects/analyze/">www.jbxue.com</a>.
** Author: Jonas John
*/
// 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.jbxue.com/');
// redrict with delay:
header('Refresh: 10; url=http://www.jbxue.com/');
print 'You will be redirected in 10 seconds';
// you could also use the HTML syntax:// <meta http-equiv="refresh" content="10;http://www.jbxue.com/ />
// 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';
?>
转载于:https://www.cnblogs.com/linuxnotes/p/3304321.html
php header函数实例代码相关推荐
- 族谱树php源代码下载,PHP下载文件的函数实例代码
通过函数完成下载文件的PHP功能代码 function download($url, $filename) { // 获得文件大小, 防止超过2G的文件, 用sprintf来读 $filesize = ...
- js Function对象扩展与延时执行函数实例代码
网页特效 function对象扩展与延时执行函数实例代码 function.prototype.delay=function(this1,timeout){ this1=this1||null; ti ...
- python嵌套函数具体案例_python编程嵌套函数实例代码
python,函数嵌套,到底是个什么东东? 很少有人用,但是,有时确实会用: def multiplier(factor): def multiplyByFactor(number): return ...
- trim函数实现php,php trim函数实例代码
在php编程中, trim() 函数从字符串的两端删除空白字符和其他预定义字符. 去掉前后的空格. 假设有一个字符串" ddd dd d ",经过trim()之后成为"d ...
- php xcopy,模拟xcopy的函数实例代码
XCOPY是COPY的扩展,可以把指定的目录连文件和目录结构一并拷贝,但不能拷贝系统文件:使用时源盘符.源目标路径名.源文件名至少指定一个:选用/S时对源目录下及其子目录下的所有文件进行COPY.除非 ...
- php中files和FILRS,PHP_php利用header函数实现文件下载时直接提示保存,复制代码 代码如下: ?php $fil - phpStudy...
php利用header函数实现文件下载时直接提示保存 复制代码 代码如下: $filename = '路径+实际文件名'; //文件的类型 header('Content-type: applicat ...
- 函数重写 java_java 函数的重载和重写实例代码
在java中多态分为两种编译时多态(重载)和运行时多态(重写),编译时多态又叫前绑定,运行时多态又叫后绑定. 下面用一个例子说明: public class OverloadAndOverwrite ...
- matlab中多元线性回归regress函数精确剖析(附实例代码)
matlab中多元线性回归regress函数精确剖析(附实例代码) 目录 前言 一.何为regress? 二.regress函数中的参数 三.实例分析 总结 前言 regress函数功能十分强大,它可 ...
- php中分页公式,php分页函数完整实例代码
本文分享一例php分页函数完整实例代码,使用此函数实现分页效果很不错.分享给大家供大家参考. 具体功能代码如下: /* * Created on 2011-07-28 * 使用方法: require_ ...
最新文章
- Subversion hooks脚本配置演示及排错
- Zookeeper 服务注册中心
- 学习笔记(二)JavaScript基本概念(语法,数据类型,控制语句,函数)
- 从Java转向.NET/C#,Are You OK?
- 如何用css和HTML结合画熊,结合伪元素实现的纯CSS3高级图形绘制
- LeetCode 1287. 有序数组中出现次数超过25%的元素
- C++ new和delete运算符
- 江西省普通高考2021艺术楼统考成绩查询,统考成绩查询
- 指纹和人脸识别 AI 总结
- 微信小程序之自定义计时器
- 看看别人家的待遇,字节跳动薪酬体系我真的酸了
- 【控制篇 / 策略】(5.4) ❀ 03. Explicit Web Proxy 显式web代理 ❀ FortiGate 防火墙
- 京版国八条终于出来了——京十五条
- linux磁盘检测工具
- 2D横版摩托游戏源码
- WLAN技术入门(二):WLAN基本概念
- springboot2.2.X手册:基于OSS解决文件存储(一年9元^^,赚了)
- 微距摄影昆虫拍摄技巧
- linux中top显示的信息详解,Linux中top显示信息详解
- 孙思邈的养生十三法[转]
热门文章
- springbootSecurity的使用
- 能发出调子的c语言程序,求关于单片机的电子琴C程序
- java 自定义报表_设计好的报表是如何在 web 上显示的
- python主成分分析法实训报告_基于 python 的主成分分析步骤及应用实例
- linux .o文件,Linux 文件I/O
- mysql脚本中如何写判断_mysql中如何写判断语句
- 怎么检测不到我的音频_新专利显示未来的AirPods可能会检测手势 并具有旋转式音量控制功能...
- linux 复制 链接文件,Linux硬链接、软连接和复制的区别
- mysql主从复制同步实验_db.mysql.主从同步实验
- java 类型转换原理_9.java数据类型的转换