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库可以简单和有效地去抓网页.你只需要运行一个脚本,然后分析一下你所抓 ...
随机推荐
- vue 组件通信传值
父子组件通信: 子组件 <template> <div> <h3 @click="alerrt"> 我是子组件一</h3> < ...
- sql server的数据库个数、表个数及表的数据量统计
sql server的数据库个数.表个数及表的数据量统计 --由于今天要监控数据,急需统计实例中1有多少库2库里有多少表3每个表有多少数据 --将写好的代码贴出来,用到如下的: --sysobje ...
- noip模拟赛 钻石
分析:用裸暴力可以得60分,每次dfs,看第i个盒子到底有没有钻石就行了.其实这很像0/1背包问题,只是多了一个m的限制.这要怎么办呢?因为概率是可以加减的,所以可以先不考虑m的限制,求出概率,然后d ...
- 【实时文件同步】rsync+inotify-tools的安装与配置
http://blog.csdn.net/yakson/article/details/52044403
- webpack教程——css的加载
首先要安装css的loader npm install css-loader style-loader --save-dev 然后在webpack.config.js中配置如下代码 意思是先用css- ...
- AngularJS:添加检查密码输入是否一致的功能
感谢作者(http://blog.brunoscopelliti.com/angularjs-directive-to-check-that-passwords-match) 利用AngularJS的 ...
- Xsolla与蜗牛一起共创黑金
Xsolla和蜗牛游戏强强合作,公布了黑金在线,是中国知名网络游戏武术时代的一个新项目. Xsolla与蜗牛黑金 2014年6月10日至20日,蜗牛的黑金在线首次在美国洛杉矶E3展会上亮相. 该游戏官 ...
- 学习笔记——WPF
WPF,Windows Presentation Foundation.主要作用在于界面呈现,但Presentation却是介绍的意思. WPF采用XAML + 代码相结合的方式,感觉跟ASP.NET ...
- oc39-- 类的内存存储
虚线是isa的指向,实线是继承关系. // // main.m // 类的本质 #import <Foundation/Foundation.h> #import "Person ...
- .Net-ASP.NET Web API:目录
ylbtech-.Net-ASP.NET Web API:目录 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 0. https://www.asp.net/we ...