您现在的位置:计算机技术学习网 > 技术中心 > WEB编程 > PHP >

php header函数使用实例代码

来源:未知 责任编辑:智问网络 发表时间:2013-10-07 00:58 点击:
  1. <?php
  2. /*** Function: PHP header() examples (PHP)
  3. ** Desc: Some examples on how to use the header() function of PHPYou find a detailed tutorial at expertsrt.com (English) or at ffm.junetz.de (German).These is also a good help about caching at web-caching.com.
  4. ** Example: see below. <br/><br/><b>Tip:</b> You can use these sites to check your headers: <a href="http://web-sniffer.net/">web-sniffer.net</a>, <a href="http://www.delorie.com/web/headers.html">delorie.com</a> or <a href="http://www.forret.com/projects/analyze/">www.forret.com</a>.
  5. ** Author: Jonas John
  6. */
  7. // fix 404 pages:
  8. header(HTTP/1.1 200 OK);
  9. // set 404 header:
  10. header(HTTP/1.1 404 Not Found);
  11. // set Moved Permanently header (good for redrictions)
  12. // use with location header
  13. header(HTTP/1.1 301 Moved Permanently);
  14. // redirect to a new location:
  15. header(Location: http://www.example.org/);
  16. // redrict with delay:
  17. header(Refresh: 10; url=http://www.example.org/);
  18. print You will be redirected in 10 seconds;
  19. // you could also use the HTML syntax:// <meta http-equiv="refresh" content="10;http://www.example.org/ />
  20. // override X-Powered-By: PHP:
  21. header(X-Powered-By: PHP/4.4.0);
  22. header(X-Powered-By: Brain/0.6b);
  23. // content language (en = English)
  24. header(Content-language: en);
  25. // last modified (good for caching)
  26. $time = time() – 60; // or filemtime($fn), etc
  27. header(Last-Modified: .gmdate(D, d M Y H:i:s, $time). GMT);
  28. // header for telling the browser that the content
  29. // did not get changed
  30. header(HTTP/1.1 304 Not Modified);
  31. // set content length (good for caching):
  32. header(Content-Length: 1234);
  33. // Headers for an download:
  34. header(Content-Type: application/octet-stream);
  35. header(Content-Disposition: attachment; filename="example.zip");
  36. header(Content-Transfer-Encoding: binary);
  37. // load the file to send:readfile(example.zip);
  38. // Disable caching of the current document:
  39. header(Cache-Control: no-cache, no-store, max-age=0, must-revalidate);
  40. header(Expires: Mon, 26 Jul 1997 05:00:00 GMT);
  41. // Date in the pastheader(Pragma: no-cache);
  42. // set content type:
  43. header(Content-Type: text/html; charset=iso-8859-1);
  44. header(Content-Type: text/html; charset=utf-8);
  45. header(Content-Type: text/plain);
  46. // plain text file
  47. header(Content-Type: image/jpeg);
  48. // JPG picture
  49. header(Content-Type: application/zip);
  50. // ZIP file
  51. header(Content-Type: application/pdf);
  52. // PDF file
  53. header(Content-Type: audio/mpeg);
  54. // Audio MPEG (MP3,…) file
  55. header(Content-Type: application/x-shockwave-flash);
  56. // Flash animation// show sign in box
  57. header(HTTP/1.1 401 Unauthorized);
  58. header(WWW-Authenticate: Basic realm="Top Secret");
  59. print Text that will be displayed if the user hits cancel or ;
  60. print enters wrong login data;
  61. ?>
    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • PHP测试
    • 十天学会php之第六天
    • 几种显示数据的方法的比较
    • 使用xmlhttp为网站增加域名查询功能
    • PHP+MYSQL+Javascript数据库查询结果的动态显示
    • 查找数组中指定键名的值
    • 用redis实现跨服务器session
    • 用新浪微博接口发送图片微博失败的原因
    • smarty局部缓存技术[源码分析]
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1