johnmahugu

php - no cache

Jun 25th, 2015
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(-1);
  4.  
  5. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  6. header("Cache-Control: no-cache, no-store, must-revalidate");
  7. header("Pragma: no-cache");
  8.  
  9. ?>
  10.  
  11. <a href="index.php">Go back to index</a>
  12. | <a href="<?php echo $_SERVER["REQUEST_URI"];?>">Refresh</a>
  13.  
  14. <title>No cache</title>
  15. <h1>No cache</h1>
  16.  
  17. <p>This example uses PHP header() calls to set cache control.</p>
  18.  
  19. Some random number:
  20. <?php echo rand(1, 1000); ?>
  21.  
  22. <p>
  23.     Go back and forward using mouse context menu to see if this number changed,
  24.     if so the cache was disabled successfully.
  25. </p>
  26.  
  27. <p>
  28.     To avoid caching of static resources put some random query string
  29.     when including js/css files, see for example:
  30. </p>
  31.  
  32. <pre style="background: #ddd;">
  33. &lt;link href="css/style.css?r=&lt;?php echo time(); ?&gt;" rel="stylesheet" type="text/css" /&gt;
  34. </pre>
Advertisement
Add Comment
Please, Sign In to add comment