php header函數用法舉例(1)

來源:互聯網
上載者:User
  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. ?>
複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.