例えば、ショッピングカートで“お買い物かご”の中味のページを表示する場合など、ブラウザのキャッシュを無効にして、必ず最新の内容を表示させたい場合があります。
キャッシュさせたくないページを直接Htmlで作る場合は、<header>タグ内のメタタグに
1 | < meta http-equiv = "Pragma" content = "no-cache" > |
2 | < meta http-equiv = "cache-control" content = "no-cache" > |
3 | < meta http-equiv = "expires" content = "0" > |
のように記述します。
PHPでヘッダ情報を出力する場合は、Htmlを出力する前に、以下のheader関数を呼びます。
1 | header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); |
2 | header( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' ); |
3 | header( 'Cache-Control: no-store, no-cache, must-revalidate' ); |
4 | header( 'Cache-Control: post-check=0, pre-check=0' , false ); |
5 | header( 'Pragma: no-cache' ); |
[…] header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); header( 'Cache-Control: no-store, no-cache, must-revalidate' ); header( 'Cache-Control: post-check=0, pre-check=0', false ); header( 'Pragma: no-cache' ); (参考) キャッシュされないページをPHPで作る […]