The "no cache" way with php on part of my page?

I have a form on the page of my site. I have a table in which echos from the submit form, which I would not want to cache, because when you enter the form, the cached version is displayed and not updated. Is there a better way not to cache the page rather than meta tags?

The code I'm using now is

<?php $query='select * from article order by `article`.`time` DESC LIMIT 10'; $result=mysql_query($query); echo '<table class="mytable" width="1000px" border="0">'; while($row = mysql_fetch_array($result)) { echo "<td><a href='".$row['url']."'>".$row['title']."</a> - ".$row['name']."</td><td>".$row['class']."</td></tr>"; } echo '<table>'; ?> 
+4
source share
4 answers
 <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past ?> 

See http://php.net/manual/en/function.header.php

+2
source

It's more complicated, but you can put your "non-cached" data in an iframe and paste the iframe into your main document.

However, if your main page is extremely large, I doubt it is worth the effort to cache only part of the page. Usually, if your css , javascript and images are external, they should be cached normally and make up the bulk of your code.

+1
source

These php headers prevent client-side caching of your php output:

 <?php //no cache headers header("Expires: Mon, 26 Jul 2012 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d MYH:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); ?> 
0
source

Using:

 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 

And caching the rest by buffering ob .

0
source

Source: https://habr.com/ru/post/1435618/


All Articles