2

I am trying to hard-refresh my page, since I randomize the order of my database, but when I refresh the page via the html button it doesn't work, until a bit of time has passed. I assume it is due to the web-browser's cache. it also doesn't work if I refresh it via f5, but if I use shift+f5 it works.

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

As you see I currently use <a href='javascript:location.reload();'>, but I have also tried javascript:window.location.href=window.location.href inside href

Tomas Berger
  • 103
  • 1
  • 12

1 Answers1

5

Using 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" />

Using php

header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0");
Abhishek Panjabi
  • 429
  • 2
  • 22
  • Can you tell ow this works? i didnt get it worked...!!!! – saleem ahmed Feb 14 '18 at 05:44
  • Your browser stores page in the cache. So if you'll refresh the page to optimize the speed the browser will show page from the cache only. So if you want to stop that. You need to tell browser that data of this page expires after some amount of time. In this case as you can see we've set it to 0 which means it expires immidiately. So browser won't store page with expired contents in cache and whenever u will hit the refresh button it'll try to get it from the server only. @saleem ahmed – Abhishek Panjabi Feb 15 '18 at 14:29