zoukankan      html  css  js  c++  java
  • 2)header的使用

     1 header() 函数向客户端发送原始的 HTTP 报头。
     2 
     3 认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数(在 PHP 4 以及更高的版本中,您可以使用输出缓存来解决此问题):
     4 
     5 <?php
     6 header('HTTP/1.1 200 OK'); // ok 正常访问
     7 header('HTTP/1.1 404 Not Found'); //通知浏览器 页面不存在
     8 header('HTTP/1.1 301 Moved Permanently'); //设置地址被永久的重定向 301
     9 header('Location: http://www.ithhc.cn/'); //跳转到一个新的地址
    10 header('Refresh: 10; url=http://www.ithhc.cn/'); //延迟转向 也就是隔几秒跳转
    11 header('X-Powered-By: PHP/6.0.0'); //修改 X-Powered-By信息
    12 header('Content-language: en'); //文档语言
    13 header('Content-Length: 1234'); //设置内容长度
    14 header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); //告诉浏览器最后一次修改时间
    15 header('HTTP/1.1 304 Not Modified'); //告诉浏览器文档内容没有发生改变
    16  
    17 ###内容类型###
    18 header('Content-Type: text/html; charset=utf-8'); //网页编码
    19 header('Content-Type: text/plain'); //纯文本格式
    20 header('Content-Type: image/jpeg'); //JPG、JPEG 
    21 header('Content-Type: application/zip'); // ZIP文件
    22 header('Content-Type: application/pdf'); // PDF文件
    23 header('Content-Type: audio/mpeg'); // 音频文件 
    24 header('Content-type: text/css'); //css文件
    25 header('Content-type: text/javascript'); //js文件
    26 header('Content-type: application/json'); //json
    27 header('Content-type: application/pdf'); //pdf
    28 header('Content-type: text/xml'); //xml
    29 header('Content-Type: application/x-shockw**e-flash'); //Flash动画
    30  
    31 ######
    32  
    33 ###声明一个下载的文件###
    34 header('Content-Type: application/octet-stream');
    35 header('Content-Disposition: attachment; filename="ITblog.zip"');
    36 header('Content-Transfer-Encoding: binary');
    37 readfile('test.zip');
    38 ######
    39  
    40 ###对当前文档禁用缓存###
    41 header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
    42 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    43 ######
    44  
    45 ###显示一个需要验证的登陆对话框### 
    46 header('HTTP/1.1 401 Unauthorized'); 
    47 header('WWW-Authenticate: Basic realm="Top Secret"'); 
    48 ######
    49  
    50  
    51 ###声明一个需要下载的xls文件###
    52 header('Content-Disposition: attachment; filename=ithhc.xlsx');
    53 header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    54 header('Content-Length: '.filesize('./test.xls')); 
    55 header('Content-Transfer-Encoding: binary'); 
    56 header('Cache-Control: must-revalidate'); 
    57 header('Pragma: public'); 
    58 readfile('./test.xls'); 
    59 ######
    60 ?>
  • 相关阅读:
    十一.SVM神经网络
    九.自组织竞争神经网络
    八.DBN深度置信网络
    七.RBM受限玻尔兹曼机
    六.随机神经网络Boltzmann(玻尔兹曼机)
    二十公里法则
    五.反馈(Hopfield)神经网络
    Python进行Android开发步骤
    django中的中间件机制和执行顺序
    简单的Python 火车抢票程序
  • 原文地址:https://www.cnblogs.com/xiaoyoucai/p/7463872.html
Copyright © 2011-2022 走看看