簡體   English   中英

將緩存頁面檢查集成到索引文件中

[英]integrate cached-page check into index file

我試圖將主頁設置為使用查詢字符串重新加載,這樣它就不會來自緩存文件。 該頁面是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().";'
}

但我不確定如何將所有內容整合在一起。

謝謝

這不一定會阻止瀏覽器緩存頁面,最好不要發送緩存頭...

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

我相信這段PHP代碼將滿足您的要求:

if ( !isset$($_COOKIE['login_cookie'] ) 
{
    //render login-form page
}
else 
{
    //redirect to the content page
    header("Location: index.php?t=" . time());
    exit();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM