Gmail / Facebook Style Chat Application
Details Live Demo Download


Posted: Sunday 30th of September 2012

PHP Send no-cache Headers



This tutorial will teach you how to prevent your pages from being cached and to avoid including so many headers at the top of your pages using a single PHP Function.
Please copy the code and paste in your global functions file that is included at the top of your website pages and call the function with a single line of code.

Code:

<?php
function PHP_DO_NOT_CACHE_HEADERS()
{
      if (!headers_sent()) //Check if header has already been sent
      {
            header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
            header('Last-Modified: ' . gmdate( 'D, d M Y H: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');
            return true;
      }
      else
      {
            return false; //Do nothing since it has already been sent
      }
}
//How to call the above function
PHP_DO_NOT_CACHE_HEADERS();
?>




That's it guys...



Comments
0

 

Announcement x
Dear Users and Clients,

This is to inform you that we have recently updated our website generally.

If you experience any problem viewing any part of this website or if you notice that any of our scripts or tutorials are not functioning properly as should be, please click on the Contact Link at the top of this page to report the issue to us.

Our priority is to give you the best of service!


Thank You,
The Vasplus Team

Announcement