php header() 函数用法归纳
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() 函数用法归纳的更多相关文章
- php header函数实例代码
一个完美的演示PHP header()函数用法的完整代码. 其中介绍的refresh方法,比<META ……用起来更得心应手,应该是段不错的代码. <?php /*** Function ...
- PHP中header函数的用法及其注意重点是什么呢
1.使用header函数进行跳转页面: header('Location:'.$url); 其中$url就是将要跳转的url了. 这种用法的注意事项有以下几点: •Location和":&q ...
- PHP header函数设置http报文头(设置头部域)
PHP HTTP 简介: HTTP 函数允许您在其他输出被发送之前,对由 Web 服务器发送到浏览器的信息进行操作. PHP 5 HTTP 函数:header() 向客户端发送原始的 HTTP ...
- PHP中的header()函数作用
PHP 中 header()函数的作用是给客户端发送头信息. 什么是头信息?这里只作简单解释,详细的自己看http协议.在 HTTP协议中,服务器端的回答(response)内容包括两部分:头信息(h ...
- PHP的ob_start()函数用法
经典参考片段: <?php ob_start(); echo '123'; echo '456'; echo '789'; $content = ob_get_contents(); ob_en ...
- PHP header() 函数详细说明(301、404等错误设置)
原文来自:http://www.veryhuo.com/a/view/41466.html 如果您刚刚开始学习PHP,可能有许多函数需要研究,今天我们就来学习一下PHP Header()的使用方法,更 ...
- php header函数要点
发布:snowfly 来源:网络 [大 中 小] 相信很多人写程序时,使用 header(location) 进行跳转往往不记得写 exit() 语句,这种做法存在严重风险. 从浏览器来看 ...
- php中setcookie函数用法详解(转)
php中setcookie函数用法详解: php手册中对setcookie函数讲解的不是很清楚,下面是我做的一些整理,欢迎提出意见. 语法: bool set ...
- php curl_init函数用法
原文地址:curl_init函数用法">php curl_init函数用法作者:loading 使用PHP的cURL库可以简单和有效地去抓网页.你只需要运行一个脚本,然后分析一下你所抓 ...
随机推荐
- Selenium的安装和简单实用——PhantomJS安装
简介 Selenium是一个用于Web应用程序测试的工具. Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE(7, 8, 9, 10, 11),Firefox,S ...
- ubuntu 14.04 gcc/g++版本降低
Matlab 2014a支持的gcc/g++版本是4.7x,而ubuntu 14.04以及更高版本默认安装的版本都是4.8及以上,因此需要降低gcc/g++版本,方法如下: 1 安装 $ sudo a ...
- Debug 集子
一. 001.c: 在函数 'main' 中: 001.c:8: 错误:'start' 的存储大小未知 001.c:9: 错误:'end' 的存储大小未知 ====================== ...
- 手工MAVEN建立WEBAPP项目并打包部署
参考URL: http://my.oschina.net/zimingforever/blog/266028 最简单的东东,可以就两条命令: 建立目录及POM.XML: mvn archetype:g ...
- [转]十五天精通WCF——第五天 你需要了解的三个小技巧
一: 服务是端点的集合 当你在开发wcf的时候,你或许已经注意到了一个service可以公布多个endpoint,确实是这样,在wcf中有一句很经典的话,叫做“服务是端点的集合",就 比如说 ...
- pthread2
下面我们来看看这个demo #include <stdio.h> #include <pthread.h> #include <unistd.h> #include ...
- angular5 httpclient的示例实战
摘要: 从angular 4.3.0 以后的版本开始使用httpclient,替换了之前的http,引用的包路径已经变为了angular/common/http了 一个基础的 httpclient 样 ...
- 利用Node.js对某智能家居server重构
原文摘自我的前端博客,欢迎大家来訪问 http://www.hacke2.cn 之前负责过一个智能家居项目的开发,外包重庆一家公司的.我们主要开发server监控和集群版管理. 移动端和机顶盒的远程通 ...
- CocoaPods建立私有仓库
项目管理:CocoaPods建立私有仓库 2015-05-08 10:22 编辑: lansekuangtu 分类:iOS开发 来源:agdsdl 0 6367 CocoaPods项目管理私有仓库 招 ...
- 杂项-Java:EL表达式
ylbtech-杂项-Java:EL表达式 EL(Expression Language) 是为了使JSP写起来更加简单.表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提 ...