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. php 漏洞分析

    addslashes() 函数返回在预定义字符之前添加反斜杠的字符串.

  2. python在Linux中安装虚拟环境,区别python2和python3,分别安装模块

    安装虚拟环境的时候遇到的问题,解决的过程很闹心,在这里简单直接的分享出来,就是为了解决问题.  安装虚拟环境(须在联网状态下) $ sudo pip install virtualenv $ sudo ...

  3. java 多线程面试题

    1.什么是线程? 线程是操作系统能够运行的最小调度单位,他被包含在进程中,是进程中实际运作的单位. 2.线程和进程的区别 线程是进程的子集,一个进程有很多线程,每个线程执行不同的任务,不同的进程使用不 ...

  4. java debug jdk(转载)

    Debug info unavailable 解决之道 从事Java的小伙伴们估计都有断点代码的习惯,可以很方便的查看运行期代码中一些变量的值. 但是JDK中有些类你会发现是无法断点的,即使你在IDE ...

  5. MSSQL的表备份成INSERT脚本的存储过程

    USE [SupplyChain]GO/****** Object: StoredProcedure [dbo].[ExpData] Script Date: 2015-12-18 10:23:08 ...

  6. HDU 4598

    这道题其实不需要考虑具体数值,但可以肯定的是,相连边的两端点必定有一正一负,至于谁正谁负,并不重要,这是可以思考的,很明显的一个二分图性质,如果不满足此条件,是不可能满足题目第二个条件的.所以首先对题 ...

  7. c++中cin的基本使用方法

    一.最主要的使用方法cin>> 接收一个数字.字符.字符串.遇"空格"."TAB"."回车"都结束 比如: <span s ...

  8. ANDROID窗体管理服务实现机制和架构分析

     一.功能 窗体管理是ANDROID框架一个重要部分,主要包含例如以下功能: )Z-ordered的维护 )窗体的创建.销毁 )窗体的绘制.布局 )Token管理,AppToken )活动窗体管理 ...

  9. 交叉熵代价函数——当我们用sigmoid函数作为神经元的激活函数时,最好使用交叉熵代价函数来替代方差代价函数,以避免训练过程太慢

    交叉熵代价函数 machine learning算法中用得很多的交叉熵代价函数. 1.从方差代价函数说起 代价函数经常用方差代价函数(即采用均方误差MSE),比如对于一个神经元(单输入单输出,sigm ...

  10. FreeWheel基于Go的实践经验漫谈——GC是大坑(关键业务场景不用),web框架尚未统一,和c++性能相比难说

    摘自:http://www.infoq.com/cn/news/2017/06/freewheel-experience-on-go Go语言是FreeWheel公司目前主要力推的一个方向,在其看来, ...