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();
?>
Click here to view this tutorial
No comments:
Post a Comment