-
PHP header函数一此常用的用法详解
在php中header函数是一个很常用的函数了,它可以跳转也可以发送各种状态代码,如404,301或者页面编码,下面我来总结一下header函数常用方法,代码如下:
- <?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.phpfensi.com/');
- // redrict with delay:
- header('Refresh: 10; url=http://www.phpfensi.com/');
- //print You will be redirected in 10 seconds;
- // you could also use the HTML syntax:// <meta http-equiv="refresh" content="10;http://www.phpfensi.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');
- // 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;
- // 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');
- php页面为utf编码
- header("Content-type: text/html; charset=utf-8");
- php页面为gbk编码
- header("Content-type: text/html; charset=gb2312");
- php页面为big5编码
- header("Content-type: text/html; charset=big5");
- Header( "HTTP/1.1 301 Moved Permanently" ) ;
- Header( "Location: www.phpfensi.com" );
- ?>
出处:http://www.phpfensi.com/php/20140913/5525.html
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比
一款纯 JS 实现的轻量化图片编辑器
关于开发 VS Code 插件遇到的 workbench.scm.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式