• 技术文章 >后端开发 >php教程

    PHP header函数使用方法讲解

    巴扎黑巴扎黑2017-03-19 09:49:48原创902
    [导读] 在php语言中,header()这个函数很有用的,尤其在用到ajax时。下面是header的一些详细讲解。<?php2 ** 3 * php header函数用法举例* 整理:www jbxue com* fix 404 pages: header(& 39;HTTP 1 1 2

    在php语言中,header()这个函数很有用的,尤其在用到ajax时。

    下面是header的一些详细讲解。

    <?php2 /** 3 * php header函数用法举例
    * 整理:www.jbxue.com
    */
    // fix 404 pages: 
    header('HTTP/1.1 200 OK'); 
    // set 404 header: 
    header('HTTP/1.1 404 Not Found'); 
    // set Moved Permanently header (good for redrictions) 
    // use with location header 
    header('HTTP/1.1 301 Moved Permanently'); 
    // redirect to a new location: 
    header('Location: http://www.jbxue.com/'); 
    // redrict with delay: 
    header('Refresh: 10; url=http://www.jbxue.com/'); 
    print 'You will be redirected in 10 seconds'; 
    // you could also use the HTML syntax:// <meta http-equiv="refresh" content="10;http://www.jbxue.com/ /> 
    // override X-Powered-By: PHP: 
    header('X-Powered-By: PHP/4.4.0'); 
    header('X-Powered-By: Brain/0.6b'); 
    // content language (en = English) 
    header('Content-language: en'); 
    // last modified (good for caching) 
    $time = time() – 60; // or filemtime($fn), etc 
    header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); 
    // header for telling the browser that the content 
    // did not get changed 
    header('HTTP/1.1 304 Not Modified'); 
    // set content length (good for caching): 
    header('Content-Length: 1234'); 
    // Headers for an download: 
    header('Content-Type: application/octet-stream'); 
    header('Content-Disposition: attachment; filename="example.zip"'); 
    header('Content-Transfer-Encoding: binary'); 
    // load the file to send:readfile('example.zip'); 
    // Disable caching of the current document: 
    header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); 
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
    // Date in the pastheader('Pragma: no-cache'); 
    // set content type: 
    header('Content-Type: text/html; charset=iso-8859-1'); 
    header('Content-Type: text/html; charset=utf-8'); 
    header('Content-Type: text/plain'); 
    // plain text file 
    header('Content-Type: image/jpeg'); 
    // JPG picture 
    header('Content-Type: application/zip'); 
    // ZIP file 
    header('Content-Type: application/pdf'); 
    // PDF file 
    header('Content-Type: audio/mpeg'); 
    // Audio MPEG (MP3,…) file 
    header('Content-Type: application/x-shockwave-flash'); 
    // Flash animation// show sign in box 
    header('HTTP/1.1 401 Unauthorized'); 
    header('WWW-Authenticate: Basic realm="Top Secret"'); 
    print 'Text that will be displayed if the user hits cancel or '; 
    print 'enters wrong login data'; 
    ?>

    以上就是 PHP header函数使用方法讲解的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇: PHP代码优化总结 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • PHP Hyperf 3.0 发布!新功能速览• 详解PHP怎么实现旋转图片验证• 简单理解PHP超级全局变量• 一起聊聊PHP的路由与伪静态应用• PHP中几种常见的开发模式
    1/1

    PHP中文网