将缓存页签入集成到索引文件中
integrate cached-page check into index file
我正在尝试将主页设置为使用查询字符串重新加载,以便它不会来自缓存文件。 该页面是索引.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();
}
相关文章:
- 限制对HTML/CSS/IMG或根索引文件夹的访问
- 文件结构:使用索引.js文件级联访问子模块或子文件
- 从文件中字符的索引中获取行号
- 使用node.js将非常大的json文件索引/摄取到数据库中
- PHP未定义的索引(由jquery文件上传引起)
- 将JSON从索引操作服务到公用文件夹中的index.html
- 节点.js socket.io 网络服务器提供索引.html以外的其他文件
- 如何删除索引中加载的脚本文件中的重复项.html和业力
- 将缓存页签入集成到索引文件中
- 第三方(随机网站访问者)是否有可能通过 php 表单更新.html索引文件中的某些.js代码
- Express+Angular,总是为html请求发送索引文件,而不是api请求
- ES6 在索引文件中导出/导入
- 索引文件到模块实例的交互
- $scope var不在索引文件中放置数据
- PhoneGap Javascript不能在索引文件中工作
- 为什么要添加所有模块来表示索引文件app.js ?
- 当与其他视图不在同一文件夹中时,Swig标记在索引文件中不起作用
- 不能在ExpressJS服务索引文件中包含JS文件
- 为什么cdn链接放在索引文件的底部
- htaccess protect只索引文件,不索引其他文件