PHP 教程
- 第1节:PHP 简介
- 第2节:PHP 安装
- 第3节:PHP 语法
- 第4节:PHP 变量
- 第5节:PHP echo和print 语句
- 第6节:PHP 数据类型
- 第7节:PHP 常量
- 第8节:PHP 字符串变量
- 第9节:PHP 运算符
- 第10节:PHP if...else 语句
- 第11节:PHP switch 语句
- 第12节:PHP 数组
- 第13节:PHP 数组排序
- 第14节:PHP 超级全局变量
- 第15节:PHP while 循环
- 第16节:PHP for 循环
- 第17节:PHP 函数
- 第18节:PHP 魔术常量
- 第19节:PHP 命名空间
- 第20节:PHP 面向对象
- 第21节:PHP 表单
- 第22节:PHP 表单验证
- 第23节:PHP 表单 - 必需字段
- 第24节:PHP 表单 - 验证邮件和URL
- 第25节:PHP 完整表单实例
- 第26节:PHP $_GET 变量
- 第27节:PHP $_POST 变量
- 第28节:PHP 多维数组
- 第29节:PHP 日期
- 第30节:PHP date() 函数
- 第31节:PHP 包含
- 第32节:PHP 文件
- 第33节:PHP 文件上传
- 第34节:PHP Cookies
- 第35节:PHP Sessions
- 第36节:PHP E-Mail
- 第37节:PHP 安全 E-mail
- 第38节:PHP 错误处理
- 第39节:PHP 异常处理
- 第40节:PHP 过滤器
- 第41节:PHP 高级过滤器
- 第42节:PHP JSON
- 第43节:PHP MySQL 简介
- 第44节:PHP 连接 MySQL
- 第45节:PHP MySQL 创建数据库
- 第46节:PHP MySQL 创建数据表
- 第47节:PHP MySQL 插入数据
- 第48节:PHP MySQL 插入多条数据
- 第49节:PHP MySQL 预处理语句
- 第50节:PHP MySQL 读取数据
- 第51节:PHP MySQL Where 子句
- 第52节:PHP MySQL Order By 关键词
- 第53节:PHP MySQL Update
- 第54节:PHP MySQL Delete From
- 第55节:PHP 数据库 ODBC
- 第56节:PHP XML Expat 解析器
- 第57节:PHP XML DOM
- 第58节:PHP XML SimpleXML
- 第59节:PHP AJAX 简介
- 第60节:PHP – AJAX 与 PHP
- 第61节:PHP 实例 AJAX 与 MySQL
- 第62节:PHP 实例 AJAX 与 XML
- 第63节:PHP 实例 AJAX 实时搜索
- 第64节:PHP 实例 AJAX RSS 阅读器
- 第65节:PHP 实例 AJAX 投票
- 第66节:PHP 5 Array 函数
- 第67节:PHP 5 Calendar 函数
- 第68节:PHP cURL 函数
- 第69节:PHP 5 Date/Time 函数
- 第70节:PHP 5 Directory 函数
- 第71节:PHP Error 和 Logging 函数
- 第72节:PHP 5 Filesystem 函数
- 第73节:PHP Filter 函数
- 第74节:PHP FTP 函数
- 第75节:PHP HTTP 函数
- 第76节:PHP Libxml 函数
- 第77节:PHP Mail 函数
- 第78节:PHP 5 Math 函数
- 第79节:PHP Misc 函数
- 第80节:PHP MySQLi 函数
- 第81节:PHP PDO
- 第82节:PHP SimpleXML 函数
- 第83节:PHP String 函数
- 第84节:PHP XML 函数
- 第85节:PHP Zip File 函数
- 第86节:PHP Timezones
- 第87节:PHP 图像处理
- 第88节:PHP 序列化/反序列化函数
- 第89节:PHP 常用header头定义
PHP 常用header头定义
在php的开发中,我们常常需要使用到header函数头来进行做标记
header() 函数向客户端发送原始的 HTTP 报头。
常用header设置列表如下:
header('HTTP/1.1 200 OK'); // ok 正常访问
header('HTTP/1.1 404 Not Found'); //通知浏览器 页面不存在
header('HTTP/1.1 301 Moved Permanently'); //设置地址被永久的重定向 301
header('Location: http://www.ithhc.cn/'); //跳转到一个新的地址
header('Refresh: 10; url=http://www.ithhc.cn/'); //延迟转向 也就是隔几秒跳转
header('X-Powered-By: PHP/6.0.0'); //修改 X-Powered-By信息
header('Content-language: en'); //文档语言
header('Content-Length: 1234'); //设置内容长度
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); //告诉浏览器最后一次修改时间
header('HTTP/1.1 304 Not Modified'); //告诉浏览器文档内容没有发生改变
###内容类型###
header('Content-Type: text/html; charset=utf-8'); //网页编码
header('Content-Type: text/plain'); //纯文本格式
header('Content-Type: image/jpeg'); //JPG、JPEG
header('Content-Type: application/zip'); // ZIP文件
header('Content-Type: application/pdf'); // PDF文件
header('Content-Type: audio/mpeg'); // 音频文件
header('Content-type: text/css'); //css文件
header('Content-type: text/javascript'); //js文件
header('Content-type: application/json'); //json
header('Content-type: application/pdf'); //pdf
header('Content-type: text/xml'); //xml格式文件
header('Content-Type: application/x-shockw**e-flash'); //Flash动画
######
###声明一个下载的文件###
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="ITblog.zip"');
header('Content-Transfer-Encoding: binary');
readfile('test.zip');
######
###对当前文档禁用缓存###
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
######
###显示一个需要验证的登陆对话框###
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
######
###声明一个需要下载的xls文件###
header('Content-Disposition: attachment; filename=ithhc.xlsx');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Length: '.filesize('./test.xls'));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile('./test.xls');
######