網頁的緩衝是由 HTTP訊息頭中的“Cache-control”來控制的,常見的取值有private、no-cache、max-age、must- revalidate等,預設為private。其作用根據不同的重新瀏覽方式分為以下幾種情況: (1) 開啟新視窗值為private、no-cache、must-revalidate,那麼開啟新視窗訪問時都會重新訪問伺服器。而如果指定了max-age值,那麼在此值內的時間裡就不會重新訪問伺服器,例如:Cache-control: max-age=5(表示當訪問此網頁後的5秒內再次訪問不會去伺服器)(2) 在地址欄斷行符號值為private或must-revalidate則只有第一次訪問時會訪問伺服器,以後就不再訪問。值為no-cache,那麼每次都會訪問。值為max-age,則在到期之前不會重複訪問。(3) 按後退按扭值為private、must-revalidate、max-age,則不會重訪問,值為no-cache,則每次都重複訪問(4) 按重新整理按扭無論為何值,都會重複訪問Cache-control值為“no-cache”時,訪問此頁面不會在Internet臨時文章夾留下頁面備份。另外,通過指定“Expires”值也會影響到緩衝。例如,指定Expires值為一個早已過去的時間,那麼訪問此網時若重複在地址欄按斷行符號,那麼每次都會重複訪問: Expires: Fri, 31 Dec 1999 16:00:00 GMT 比如:禁止頁面在IE中緩衝HTTP響應訊息頭部設定:CacheControl = no-cachePragma=no-cacheExpires = -1Expires是個好東東,如果伺服器上的網頁經常變化,就把它設定為-1,表示立即到期。如果一個網頁每天淩晨1點更新,可以把Expires設定為第二天的淩晨1點。當HTTP1.1伺服器指定 CacheControl = no-cache時,瀏覽器就不會緩衝該網頁。舊式 HTTP 1.0 伺服器不能使用 Cache-Control 標題。所以為了向後相容 HTTP 1.0 伺服器,IE使用Pragma:no-cache 標題對 HTTP 提供特殊支援。如果用戶端通過安全連線 (https://)/ 與伺服器通訊,且伺服器在響應中返回 Pragma:no-cache 標題,則 Internet Explorer不會緩衝此響應。注意:Pragma:no-cache 僅當在安全連線中使用時才防止緩衝,如果在非安全頁中使用,處理方式與 Expires:-1相同,該頁將被緩衝,但被標記為立即到期header常用指令header分為三部分:第一部分為HTTP協議的版本(HTTP-Version);第二部分為狀態碼(Status);第三部分為原因短語(Reason-Phrase)。 // 向瀏覽器發送404 狀態代碼header(“HTTP/1.1 404 Not Found”);或者header(“HTTP/1.1 404″);// 永久重新導向header(“Location: http://hi.baidu.com/3800_hk”);//預設是301 跳轉// 臨時重新導向header(“HTTP/1.1 302 Found”);header(“Location: http://hi.baidu.com/3800_hk”);// 下載檔案header(“Content-type: text/plain’); // 可以替換成你需要的MIME類型header(‘Content-Disposition: attachment; filename=”weizhifeng.txt”‘);readfile(‘weizhifeng.txt’);其他的頭資訊可以參考HTTP/1.1 specification如果在header之前已經有了輸出,那麼請使用ob_start()函數。// override X-Powered-By: PHP:header('X-Powered-By: PHP/4.4.0');header('X-Powered-By: Brain/0.6b');//文檔語言header('Content-language: en');//告訴瀏覽器最後一次修改時間$time=time() -60; // or filemtime($fn), etcheader('Last-Modified: '.gmdate('D, d M Y H:i:s',$time).' GMT');//告訴瀏覽器文檔內容沒有發生改變header('HTTP/1.1 304 Not Modified');//設定內容長度header('Content-Length: 1234');//設定為一個下載類型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');// 對當前文檔禁用緩衝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');//設定內容類型:header('Content-Type: text/html; charset=iso-8859-1');header('Content-Type: text/html; charset=utf-8');header('Content-Type: text/plain'); //純文字格式header('Content-Type: image/jpeg'); //JPG圖片header('Content-Type: application/zip'); // ZIP檔案header('Content-Type: application/pdf'); // PDF檔案header('Content-Type: audio/mpeg'); // 音頻檔案header('Content-Type: application/x-shockwave-flash'); //Flash動畫//顯示登陸對話方塊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';?>