duannue2455 2018-08-26 20:02
浏览 53

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

I made this simple calender for a few friends to fill in all their dates, It all works fine when you update the dates but then when you go back to the calendar it shows all the old dates selected. You have to manually refresh the page to get the updated dates it's really frustrating.

You can demo it here: http://olli460.com/poker/index.php

If you click "Add/Edit Dates" then click on "oliver" and select a few random dates. When you go back to the calendar it's still showing all the old dates until you press F5.

This is my index.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>

After they enter the dates i'm using this to redirect back to the main page, is this the issue?

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

1条回答 默认 最新

  • dpj0015 2018-08-26 20:16
    关注

    if you want to fix that script, tell the browser not to cache the page:

    <?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");
    ?>
    

    and why load data from mySQL? maybe use the Google Client Library (GitHub) instead?

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)