【问题标题】:Html/php hard refresh [duplicate]Html / php硬刷新[重复]
【发布时间】:2016-09-16 04:16:47
【问题描述】:

我正在尝试硬刷新我的页面,因为我随机化了我的数据库的顺序,但是当我通过 html 按钮刷新页面时它不起作用,直到过了一段时间。我认为这是由于网络浏览器的缓存。如果我通过 f5 刷新它也不起作用,但如果我使用 shift+f5 则它可以工作。

<?php
if(isset($_GET["genre"])) {
$db = mysqli_connect("localhost","localhost","","test","3306");
$genre = $_GET["genre"];
$sql = "SELECT tittel, aar, id, genre, plot FROM gruppe3_film WHERE genre LIKE '%$genre%' ORDER BY RAND()";
$resultat = mysqli_query($db, $sql);

$rad = mysqli_fetch_assoc($resultat);
    $tittel = $rad['tittel'];
    $aar = $rad['aar'];
    $id = $rad['id'];
    $plot = $rad['plot'];
    echo "
   <h2>$tittel ($aar)</h2>
   <br><a href='javascript:location.reload();'><img src='../image/DBFilmCover/$id.jpg'></a>
   <h4>$plot</h4>
   <hr><button><a href='javascript:location.reload();'><div class='black'>New Random $genre Movie</div></a></button>";
?>

如你所见,我目前使用 &lt;a href='javascript:location.reload();'&gt;,但我也尝试过在 href 中使用 javascript:window.location.href=window.location.href

【问题讨论】:

标签: php html page-refresh


【解决方案1】:

使用 html4

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

使用php

header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0");

【讨论】:

  • 你能告诉我这行得通吗?我没有得到它的工作......!!!!
  • 您的浏览器将页面存储在缓存中。因此,如果您刷新页面以优化速度,浏览器将仅显示缓存中的页面。所以如果你想阻止它。您需要告诉浏览器该页面的数据在一段时间后过期。在这种情况下,如您所见,我们已将其设置为 0,这意味着它会立即过期。所以浏览器不会在缓存中存储过期内容的页面,每当你点击刷新按钮时,它只会尝试从服务器获取它。 @saleem ahmed
猜你喜欢
  • 2012-05-23
  • 1970-01-01
  • 1970-01-01
  • 2013-07-19
  • 2016-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-02
相关资源
最近更新 更多