我正在尝试将主页设置为使用查询字符串重新加载,以便它不会来自缓存文件。 该页面是索引.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();
}