Loading...
 
Gmail / Facebook Style Chat Application


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...


Views Today: 1
Total Views: 795

Comments
0
OUR OBJECTIVE

Our objective is to reach a place where our services will be highly regarded by businesses from various industrial domains for building their innovative busines solutions with our cutting-edge technological expertise, interactive designs and uncompromised quality.

OUR MISSION

We aspire to help businesses ranging from startups to enterprises, who reach out to us with their requirements, in achieving great lengths, expanding their reach, upscaling their products, and generate a large user-base with our outstanding and cost-effective services.

Copyright © 2011 - 2024 | All Rights Reserved