301 永久重定向
<?php
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.example.com');
exit();
?>
302 临时重定向
<?php
header('Location: http://www.example.com');
exit();
?>
404 页面未找到
<?php
header('HTTP/1.1 404 Not Found');
?>
503 服务不可用
<?php
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
exit();
?>
设置内容类型
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain'); //纯文本格式
header('Content-Type: image/jpeg'); //JPG图片
header('Content-Type: application/zip'); // ZIP文件
header('Content-Type: application/pdf'); // PDF文件
header('Content-Type: audio/mpeg'); // 音频文件
header('Content-Type: application/x-shockwave-flash'); //Flash动画
css header
<?php
header('Content-Type: text/css');
?>
javascript header
<?php
header('Content-Type: application/javascript');
?>
images header
<?php
header('Content-Type: images/jpeg');
// header('Content-Type: images/png');
// header('Content-Type: images/bmp');
?>
PDF header
<?php
header('Content-Type: application/pdf');
echo file_get_contents('filename.pdf');
?>
缓存(cache)(force browsers not to cache files)
<?php
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: not-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Pragma: no-cache'); // For IE Browsers
?>
文件下载
<?php
header('Content-Disposition: attachment;filename=' . urlencode($f));
header('Content-Type: application/force-download');
header('Content-Type: application/octet-stream');
header('Content-Type: application/download');
header('Content-Description: File Transfer');
header('Content-Length: '. filesize($f)');
echo file_get_contents($f);
?>
权限认证(force the browsers to pop up a Username/Password input window) - only available when PHP is runnig as an Apache module:
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="The Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'If cancel is pressed this text shows';
exit();
} else {
$user='user';
$pass='pass';
if($_SERVER['PHP_AUTH_USER']==$user && $_SERVER['PHP_AUTH_PW']==$pass){
echo 'Authorized';
}
}

php header() 函数用法归纳的更多相关文章

  1. php header函数实例代码

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

  2. PHP中header函数的用法及其注意重点是什么呢

    1.使用header函数进行跳转页面: header('Location:'.$url); 其中$url就是将要跳转的url了. 这种用法的注意事项有以下几点: •Location和":&q ...

  3. PHP header函数设置http报文头(设置头部域)

    PHP HTTP 简介: HTTP 函数允许您在其他输出被发送之前,对由 Web 服务器发送到浏览器的信息进行操作. PHP 5 HTTP 函数:header()     向客户端发送原始的 HTTP ...

  4. PHP中的header()函数作用

    PHP 中 header()函数的作用是给客户端发送头信息. 什么是头信息?这里只作简单解释,详细的自己看http协议.在 HTTP协议中,服务器端的回答(response)内容包括两部分:头信息(h ...

  5. PHP的ob_start()函数用法

    经典参考片段: <?php ob_start(); echo '123'; echo '456'; echo '789'; $content = ob_get_contents(); ob_en ...

  6. PHP header() 函数详细说明(301、404等错误设置)

    原文来自:http://www.veryhuo.com/a/view/41466.html 如果您刚刚开始学习PHP,可能有许多函数需要研究,今天我们就来学习一下PHP Header()的使用方法,更 ...

  7. php header函数要点

    发布:snowfly   来源:网络     [大 中 小] 相信很多人写程序时,使用 header(location) 进行跳转往往不记得写 exit() 语句,这种做法存在严重风险. 从浏览器来看 ...

  8. php中setcookie函数用法详解(转)

    php中setcookie函数用法详解:        php手册中对setcookie函数讲解的不是很清楚,下面是我做的一些整理,欢迎提出意见.        语法:        bool set ...

  9. php&nbsp;curl_init函数用法

    原文地址:curl_init函数用法">php curl_init函数用法作者:loading 使用PHP的cURL库可以简单和有效地去抓网页.你只需要运行一个脚本,然后分析一下你所抓 ...

随机推荐

  1. webpack-dev-server和webpack

    指导小伙伴在webstorm+nodejs环境下新建项目时,小伙伴出现了一个很神奇的问题:没有执行webpack-dev-server情况下,即使执行npm init,也不会出现package.jso ...

  2. 【hiho一下 第146周】子矩阵求和

    [题目链接]:http://hihocoder.com/contest/hiho146/problem/1 [题意] [题解] 设s[i][j]表示左上角的坐标为(i,j)的n*m的矩阵的和; 有s[ ...

  3. Maven学习总结(6)——Maven与Eclipse整合

    Maven学习总结(六)--Maven与Eclipse整合 一.安装Maven插件 下载下来的maven插件如下图所示:,插件存放的路径是:E:/MavenProject/Maven2EclipseP ...

  4. ZOJ 3199 Longest Repeated Substring

    Longest Repeated Substring Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on Z ...

  5. Alliances

    树国是一个有n个城市的国家,城市编号为1∼n.连接这些城市的道路网络形如一棵树, 即任意两个城市之间有恰好一条路径.城市中有k个帮派,编号为1∼k.每个帮派会占据一些城市,以进行非法交易.有时帮派之间 ...

  6. CF410div2 A. Mike and palindrome

    /* CF410div2 A. Mike and palindrome http://codeforces.com/contest/798/problem/A 水题 */ #include <c ...

  7. 文件上传-jquery.uploadify.js

    <script type="text/javascript" src="../jquery_uploadify/jquery.uploadify-3.1.min.j ...

  8. iOS:制作左右侧滑(抽屉式)菜单

    感谢控件作者:https://github.com/SocialObjects-Software/AMSlideMenu 首先上效果图: 这里我们使用AMSlideMenu来实现左右侧滑菜单的效果.控 ...

  9. C语言编程入门——程序练习(上)

    大家能够敲写一下以下的练习代码.看下执行结果,都非常easy.关键要理解. if: # include <stdio.h> int main(void) { int i = 1; i = ...

  10. B4010 菜肴制作 拓扑排序(附随机跳题代码)

    今天写了一个自己的随机跳题小程序,第一次试发现跳的全是不可做题,但是在周围我一眼看见了这个题,不能说一眼看出来,但是也是比较有思路,所以就做他了! 做得比较顺利,做完之后美滋滋,突然发现样例第三组过不 ...