php 瀏覽器不快取頁面,後退或history.go(-1)是載入新頁面同時也是瀏覽不留痕
阿新 • • 發佈:2019-01-23
//禁止快取頁面 防止訂單頁面不給錢直接返回鍵 導致購物車中生成訂單的商品還存在
$time = time() - 60*60*24;// or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
header("Expires:".gmdate("l d F Y H:i:s").' GMT');
header("Pragma: no-cache");
$time = time() - 60*60*24;// or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
header("Expires:".gmdate("l d F Y H:i:s").' GMT');
header("Pragma: no-cache");
C('HTTP_CACHE_CONTROL','no-cache,no-store,must-revalidate');//紅色才是重點
Cache-Control: no-cache:這個很容易讓人產生誤解,使人誤以為是響應不被快取。實際上Cache-Control: no-cache是會被快取的,只不過每次在向客戶端(瀏覽器)提供響應資料時,快取都要向伺服器評估快取響應的有效性。
Cache-Control: no-store:這個才是響應不被快取的意思。
Pragma: no-cache:跟Cache-Control: no-cache相同,Pragma: no-cache相容http 1.0 ,Cache-Control: no-cache是http 1.1提供的。因此,Pragma: no-cache可以應用到http 1.0 和http 1.1,而Cache-Control: no-cache只能應用於http 1.1.