Discuz教程网

PHP header()函数的应用

[复制链接]
精华
authicon 星火燎原 发表于 2011-5-21 22:32:49 | 显示全部楼层 |阅读模式
  1. 备注:使用header()函数前,不能有任何输出,前面放个ob_start就行了   
  2. // ok   
  3. header('HTTP/1.1 200 OK');   
  4.   
  5. //设置一个404头:   
  6. header('HTTP/1.1 404 Not Found');   
  7.   
  8. //设置地址被永久的重定向   
  9. header('HTTP/1.1 301 Moved Permanently');   
  10.   
  11. //转到一个新地址   
  12. header('Location: http://www.example.org/');   
  13.   
  14. //文件延迟转向:   
  15. header('Refresh: 10; url=http://www.example.org/');   
  16. print 'You will be redirected in 10 seconds';   
  17.   
  18. //当然,也可以使用html语法实现   
  19. // <meta http-equiv="refresh" content="10;http://www.example.org/ />   
  20.   
  21. // override X-Powered-By: PHP:   
  22. header('X-Powered-By: PHP/4.4.0');   
  23. header('X-Powered-By: Brain/0.6b');   
  24.   
  25. //文档语言   
  26. header('Content-language: en');   
  27.   
  28. //告诉浏览器最后一次修改时间   
  29. $time = time() - 60; // or filemtime($fn), etc   
  30. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');   
  31.   
  32. //告诉浏览器文档内容没有发生改变   
  33. header('HTTP/1.1 304 Not Modified');   
  34.   
  35. //设置内容长度   
  36. header('Content-Length: 1234');   
  37.   
  38. //设置为一个下载类型   
  39. header('Content-Type: application/octet-stream');   
  40. header('Content-Disposition: attachment; filename="example.zip"');   
  41. header('Content-Transfer-Encoding: binary');   
  42. // load the file to send:   
  43. readfile('example.zip');   
  44.   
  45. // 对当前文档禁用缓存   
  46. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');   
  47. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past   
  48. header('Pragma: no-cache');   
  49.   
  50. //设置内容类型:   
  51. header('Content-Type: text/html; charset=iso-8859-1');   
  52. header('Content-Type: text/html; charset=utf-8');   
  53. header('Content-Type: text/plain'); //纯文本格式   
  54. header('Content-Type: image/jpeg'); //JPG***   
  55. header('Content-Type: application/zip'); // ZIP文件   
  56. header('Content-Type: application/pdf'); // PDF文件   
  57. header('Content-Type: audio/mpeg'); // 音频文件   
  58. header('Content-Type: application/x-shockw**e-flash'); //Flash动画   
  59.   
  60. //显示登陆对话框   
  61. header('HTTP/1.1 401 Unauthorized');   
  62. header('WWW-Authenticate: Basic realm="Top Secret"');   
  63. print 'Text that will be displayed if the user hits cancel or ';   
  64. print 'enters wrong login data';  
复制代码




上一篇:JS 进度条效果实现代码整理
下一篇:PHP字符串处理函数大全
authicon 乐娃娃 发表于 2011-5-27 06:59:30 | 显示全部楼层
谢谢,学习了
authicon melody0721 发表于 2011-6-16 11:18:56 | 显示全部楼层
继续来索要
authicon mjz 发表于 2011-6-17 13:00:01 | 显示全部楼层
看一下啊,嘻嘻
authicon shakesxia 发表于 2011-6-23 10:59:57 | 显示全部楼层
这个还是不错的!
authicon NicoleOnly 发表于 2011-6-24 11:59:41 | 显示全部楼层
哈哈  收了你
authicon 陶衣小可 发表于 2011-6-27 12:59:40 | 显示全部楼层
看一下啊,嘻嘻
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 03:30

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表