php header示例代码(推荐)

2015-01-24信息快讯网

一个完美的演示PHP header()函数用法的完整代码。其中介绍的refresh方法,比<META ……用起来更得心应手,应该是段不错的代码。

<?php 
/*** 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.delorie.com/web/headers.html">delorie.com</a> or <a href="http://www.forret.com/projects/analyze/">www.forret.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.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() C 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中call_user_func_array()函数的用法演示
PHP中register_globals参数为OFF和ON的区别(register_globals 使用详解)
PHP函数spl_autoload_register()用法和__autoload()介绍
非常好用的两个PHP函数 serialize()和unserialize()
php木马webshell扫描器代码
php addslashes及其他清除空格的方法是不安全的
用phpmailer实现简单openvpn用户认证的实现代码
php中可能用来加密字符串的函数[base64_encode、urlencode、sha1]
PHP CURL模拟登录新浪微博抓取页面内容 基于EaglePHP框架开发
Trying to clone an uncloneable object of class Imagic的解决方法
Uncaught exception com_exception with message Failed to create COM object
url decode problem 解决方法
php urlencode()与urldecode()函数字符编码原理详解
PHP性能优化准备篇图解PEAR安装
PHP循环语句笔记(foreach,list)
用PHP写的基于Memcache的Queue实现代码
DISCUZ在win2003环境下 Unable to access ./include/common.inc.php in... 的问题终极解决方案
一个PHP的QRcode类与大家分享
PHP下利用shell后台运行PHP脚本,并获取该脚本的Process ID的代码
PHP 命令行工具 shell_exec, exec, passthru, system详细使用介绍
PHP获取表单textarea数据中的换行问题
php下清空字符串中的HTML标签的代码
PHP下利用header()函数设置浏览器缓存的代码
使用bcompiler对PHP文件进行加密的代码
php Notice: Undefined index 错误提示解决方法
php下正则来匹配dede模板标签的代码
php中使用ExcelFileParser处理excel获得数据(可作批量导入到数据库使用)
利用Memcached在php下实现session机制 替换PHP的原生session支持
ThinkPHP中实例Model方法的区别说明
php checkbox 取值详细说明
php include加载文件两种方式效率比较
php简单提示框alert封装函数
PHP通过header实现文本文件下载的代码
ubuntu 编译安装php 5.3.3+memcache的方法
PHP Stream_*系列函数
PHP 数组遍历方法大全(foreach,list,each)
《Head First 设计模式》代码之PHP版(面向对象学习)第1/2页
©2014-2024 dbsqp.com