加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php header函数用法示例

发布时间:2020-05-25 04:47:23 所属栏目:PHP 来源:互联网
导读:php header函数用法示例

本代码演示了php中header函数的详细用法,php修改http header演示,感兴趣的小伙伴,下面一起跟随脚本之家 jb51.cc的小编来看看吧。
经测试代码如下:


/**
 * header函数的用法
 *
 * @param 
 * @arrange (512.笔记) jb51.cc
 **/

//查看相关链接以获取更多状态代码
//使用此标头指令修复404标头
//由url重写生成...
header('HTTP/1.1 200 OK');
 
//找不到页面:
header('HTTP/1.1 404 Not Found');
 
//访问被禁止:
header('HTTP/1.1 403 Forbidden');
 
//永久移动的页面应该用于
//所有重新编辑,因为搜索引擎知道
//发生了什么,可以轻松更新他们的网址。
header('HTTP/1.1 301 Moved Permanently');
 
// 服务器错误
header('HTTP/1.1 500 Internal Server Error');
 
//重定向到新位置:
header('Location: http://www.example.org/');
 
//延迟重定向:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';
 
//您也可以使用HTML语法:
// <meta http-equiv="refresh" content="10;http://www.example.org/ />
 
//覆盖X-Powered-By值
header('X-Powered-By: PHP/4.4.0');
header('X-Powered-By: Brain/0.6b');
 
//内容语言(en =英语)
header('Content-language: en');
 
//最后修改(适合缓存)
$time = time() - 60; // or filemtime($fn),etc
header('Last-Modified: '.gmdate('D,d M Y H:i:s',$time).' GMT');
 
//标题用于告诉浏览器该内容
//没有改变
header('HTTP/1.1 304 Not Modified');
 
//设置内容长度(适合缓存):
header('Content-Length: 1234');
 
//下载标题:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"'); 
header('Content-Transfer-Encoding: binary');

//加载要发送的文件:
readfile('example.zip');
 
//禁用当前文档的缓存:
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 past
header('Pragma: no-cache');
 
//设置内容类型:
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
 
//显示登录框
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';


/***   来自脚本之家 jb51.cc(jb51.cc)   ***/

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读