php header函數用法舉例(1)

WBOY
發布: 2016-07-25 08:56:20
原創
818 人瀏覽過
  1. print“”; //通常读取的是缓存文件

  2. ?>
  3. print“”; //增加了唯一的编号,使浏览器重新请求

  4. w//print“”;

  5. ?>

复制代码

2,自定义php函数,将图片传送给浏览器显示。

  1. function PE_img_by_path($PE_imgpath = “”)
  2. {
  3. if (file_exists($PE_imgpath)) {
  4. $PE_imgarray = pathinfo($PE_imgpath);
  5. $iconcontent = file_get_contents($PE_imgpath);
  6. header(“Content-type: image/” . $PE_imgarray["extension"]);
  7. header(‘Content-length: ‘ . strlen($iconcontent));
  8. echo $iconcontent;
  9. die(0);
  10. }
  11. return false;
  12. }
  13. ?>
复制代码

更多实例:

  1. // ok
  2. header(‘HTTP/1.1 200 OK’);
  3. //设置一个404头:
  4. header(‘HTTP/1.1 404 Not Found’);
  5. //设置地址被永久的重定向
  6. header(‘HTTP/1.1 301 Moved Permanently’);
  7. //转到一个新地址
  8. header(‘Location: http://bbs.it-home.org/’);
  9. //文件延迟转向:
  10. header(‘Refresh: 10; url=http://bbs.it-home.org/’);
  11. print ‘You will be redirected in 10 seconds’;
  12. //当然,也可以使用html语法实现
  13. //
  14. // override X-Powered-By: PHP:
  15. header(‘X-Powered-By: PHP/4.4.0′);
  16. header(‘X-Powered-By: Brain/0.6b’);
  17. //文档语言
  18. header(‘Content-language: en’);
  19. //告诉浏览器最后一次修改时间
  20. $time = time() – 60; // or filemtime($fn), etc
  21. header(‘Last-Modified: ‘.gmdate(‘D, d M Y H:i:s’, $time).’ GMT’);
  22. //告诉浏览器文档内容没有发生改变
  23. header(‘HTTP/1.1 304 Not Modified’);
  24. //设置内容长度
  25. header(‘Content-Length: 1234′);
  26. //设置为一个下载类型
  27. header(‘Content-Type: application/octet-stream’);
  28. header(‘Content-Disposition: attachment; filename=”example.zip”‘);
  29. header(‘Content-Transfer-Encoding: binary’);
  30. // load the file to send:
  31. readfile(‘example.zip’);
  32. // 对当前文档禁用缓存
  33. header(‘Cache-Control: no-cache, no-store, max-age=0, must-ridate’);
  34. header(‘Expires: Mon, 26 Jul 1997 05:00:00 GMT’); // Date in the past
  35. header(‘Pragma: no-cache’);
  36. //设置内容类型:
  37. header(‘Content-Type: text/html; charset=iso-8859-1′);
  38. header(‘Content-Type: text/html; charset=utf-8′);
  39. header(‘Content-Type: text/plain’); //纯文本格式
  40. header(‘Content-Type: image/jpeg’); //JPG图片
  41. header(‘Content-Type: application/zip’); // ZIP文件
  42. header(‘Content-Type: application/pdf’); // PDF文件
  43. header(‘Content-Type: audio/mpeg’); // 音频文件
  44. header(‘Content-Type: application/x-shockwave-flash’); //Flash动画
  45. //显示登陆对话框
  46. header(‘HTTP/1.1 401 Unauthorized’);
  47. header(‘WWW-Authenticate: Basic realm=”Top Secret”‘);
  48. print ‘Text that will be displayed if the user hits cancel or ‘;
  49. print ‘enters wrong login data’;
  50. ?>
复制代码


來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!