• header函数的用法


    header — 发送原生 HTTP 头

    语法:void header ( string $string [, bool $replace = true [, int $http_response_code ]] )

    注意内容:header() 必须在任何实际输出之前调用,不管是普通的 HTML 标签,还是文件或 PHP 输出的空行,空格

    几种常见的用法:

    header('Location:'.$url);//跳转页面

    header('content-type:text/html;charset=utf-8');//声明content-type

    header('Refresh: 10; url=http://www.baidu.com/');//10s后跳转页面

    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");//控制浏览器缓存

    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");

    header("Cache-Control: no-cache, must-revalidate");

    header("Pragma: no-cache");

     此处提供示例代码:

    function http_10_cache_headers($lifeTime=null){

    $gmtime=time();

    if($lifeTime){

                header("Pragma: no-cache");

        }else{

                $gmtime+=$lifeTime;

                 $gmtime=gmdate('D,d,M Y H:i:S',$gmtime).'GMT';

                  header("Last-Modified:$gmtime");

                  header("Expires:$gmtime");

         }

    }

    header('HTTP/1.1 401 Unauthorized');//执行http验证

    header('WWW-Authenticate: Basic realm="Top Secret"');

    //执行下载操作

    header('Content-Type: application/octet-stream'); //设置内容类型

    header('Content-Disposition: attachment; filename="example.zip"'); //设置MIME用户作为附件

    header('Content-Transfer-Encoding: binary'); //设置传输方式

    header('Content-Length: '.filesize('example.zip')); //设置内容长度

  • 相关阅读:
    高性能无锁队列,代码注释
    阿里mysql同步工具otter的docker镜像
    webgl鱼眼算法
    国际网络环境对库的影响
    newlisp
    java面试之数据库
    java面试之遇到过的问题
    java面试之springboot
    git常用命令
    java面试之jenkins
  • 原文地址:https://www.cnblogs.com/zhirusi/p/7550225.html
Copyright © 2020-2023  润新知