0

キャッシュされたファイルから取得されないように、クエリ文字列でリロードするようにメインページを設定しようとしています。ページはindex.phpですが、ページが読み込まれるたびに、一意の文字列が追加されます(私の前の質問に対するRocketのコメントの回答のように)。

ログインを認証するphpに統合したいと思います。

このようなものは良い考えですか

<?php

require_once('login-config.php');

//use javascript cookie to detect if the page is coming from hash
//and if so, redirect to a new url with a ?<?=time()?> query sting

if ( !isset$($_COOKIE['login_cookie'] ) 
{

//render login-form page

} 
else 
{

//redirect to the content page

}

このページからのjavascriptキャッシュ/Cookieチェック(次のように)

var uniqueKey = '<%= SomeUniqueValueGenerator() %>';
var currentCookie = getCookie(uniqueKey);
var isCached = currentCookie !== null;
setCookie(uniqueKey); //cookies should be set to expire 
                      //in some reasonable timeframe

私はこのようなことをすべきだと思います、

//best guess is that I update this uniqueKey every time I update the page
//and want it not to load from cache
var uniqueKey = 'v1.1';
var currentCookie = getCookie(uniqueKey);
var isCached = currentCookie !== null;

if (!isCashed){      
    setCookie(uniqueKey);  
    window.location'?".time().";'
} else {
    window.location'?".time().";'
}

しかし、私はそれをすべてまとめる方法が正確に少しわかりません。

ありがとう

4

2 に答える 2

1

これは必ずしもブラウザによるページのキャッシュを停止するわけではありません。キャッシュヘッダーを送信しない方がよいでしょう...

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
于 2012-05-31T15:27:32.510 に答える
0

私はこのPHPコードがあなたが望むことをするだろうと信じています:

if ( !isset$($_COOKIE['login_cookie'] ) 
{
    //render login-form page
}
else 
{
    //redirect to the content page
    header("Location: index.php?t=" . time());
    exit();
}
于 2012-05-31T15:37:48.713 に答える