如何阻止这个简单的 php 日历缓存旧日期?



我为几个朋友制作了这个简单的日历来填写他们所有的日期,当您更新日期时,一切都可以正常工作,但是当您返回日历时,它会显示所有选择的旧日期。您必须手动刷新页面才能获得更新日期,这真的很令人沮丧。

您可以在此处演示:http://olli460.com/poker/index.php

如果单击"添加/编辑日期",请单击"oliver"并选择几个随机日期。当您返回到日历时,它仍显示所有旧日期,直到您按 F5。

这是我的索引.php

<?php
date_default_timezone_set('Europe/London');
//error_reporting(E_ALL);
$pageWeb = $_REQUEST['page'];
$pageWeb = filter_var($pageWeb, FILTER_SANITIZE_STRING);
if(empty($pageWeb)) {
$pageWeb = "main";
}
$mysqli = mysqli_connect("localhost","xxxxx","xxxxxx","xxxxxx") or die("Error " . mysqli_error($link)); 
?>

<!DOCTYPE html>
<html lang="en">
<head>

<title>Poker Calendar</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.0.47/jquery.fancybox.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.0.47/jquery.fancybox.min.js"></script>
<link rel="shortcut icon" sizes="192x192" href="if_icon-82_667352.png">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!--<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">-->
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Arvo:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="theme.css">
<link rel="stylesheet" type="text/css" href="style.css"> 
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
</head>
<body>
<script src="https://use.fontawesome.com/8a36931ffe.js"></script>

<div class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a href="index.php" class="navbar-brand">Poker Calendar</a>
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="navbar-main">
<ul class="nav navbar-nav">
<li <?php if(empty($pageWeb)) { echo "class="active""; } ?>><a href="index.php"><i class="fa fa-calendar" aria-hidden="true"></i>&nbsp;&nbsp;Calendar</a></li>
<li <?php if(empty($pageWeb) OR $pageWeb == "add-dates") { echo "class="active""; } ?>><a href="index.php?page=add-dates"><i class="fa fa-calendar-plus-o" aria-hidden="true"></i>&nbsp;&nbsp;Add/Edit Dates</a></li>
<li <?php if(empty($pageWeb) OR $pageWeb == "add-player") { echo "class="active""; } ?>><a href="index.php?page=add-player"><i class="fa fa-user-plus" aria-hidden="true"></i>&nbsp;&nbsp;Add Player</a></li>
</div>
</div>
</div>
<div class="clearfix"></div>
<br /><br /><br /><br />

<div class="container-fluid">
<!-- START ALL CONTENT HERE -->
<?php
if(isSet($pageWeb)){
if (!(strpos($pageWeb, "http") === false)){
echo "not allowed";
}else{
include("$pageWeb.php");
}
} else {
include("main.php");
}
?>
<!-- END ALL CONTENT HERE -->
</div>
</body>
</html>

在他们输入我使用它重定向回主页的日期后,这是问题所在吗?

<script>
$(document).ready(function () {
// Handler for .ready() called.
window.setTimeout(function () {
location.href = "index.php";
}, 3000);
});
</script>

如果要修复该脚本,请告诉浏览器不要缓存页面:

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

为什么要从mySQL加载数据?也许使用Google客户端库(GitHub(代替?

最新更新