How to prevent the browser from using cached pages in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 10:14:44
Original
813 people have browsed it

How to prevent browsers from caching pages in php

Sometimes page caching is not needed. We can prohibit browsers from caching pages.

In PHP, you can easily use the following statement to disable page caching, but it is difficult to remember and organize it for everyone’s convenience.
The php code is as follows:

The code is as follows:
//Set the expiration time of this page (expressed in Greenwich Mean Time), as long as it is a date that has passed.
header ( " Expires: Mon, 26 Jul 1970 05:00:00 GMT " );
//Set the last updated date of this page (expressed in Greenwich Mean Time) to the current day to force the browser to obtain the latest information
header ( " Last-Modified: " . gmdate ( " D, d M Y H:i:s " ). "GMT " );

// Tell the client browser not to use cache, HTTP 1.1 protocol
header ( " Cache-Control: no-cache, must-revalidate " );

// Tell the client browser not to use cache and be compatible with HTTP 1.0 protocol
header ( " Pragma: no-cache " );
?>


This is useful for certain pages, such as order information and products under the order, and clearing the corresponding product data in the shopping cart.
You definitely don’t want the user to reach the last page, have already generated an order, and then click the browser’s return button to return to the previous page.
Then add it on the order address page:

The code is as follows:
header("Cache-Control:no-cache,must-revalidate,no-store"); //After adding this no-store, it will be valid in Firefox
header("Pragma:no-cache");
header("Expires:-1");


This page is no longer cached, and there is a page that jumps to the empty shopping cart if the items in the shopping cart are empty. Then the user clicks the browser to go back, and when he comes back, he goes directly to the shopping cart page.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/907714.htmlTechArticlephp method to prohibit browsers from using cached pages Page caching is sometimes not needed, we can prohibit browsing The server caches the page. In PHP, you can easily use the following statement to implement...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template