Home > Backend Development > PHP Tutorial > PHP prohibits the browser from using cached pages, PHP prohibits caching pages_PHP tutorial

PHP prohibits the browser from using cached pages, PHP prohibits caching pages_PHP tutorial

WBOY
Release: 2016-07-13 10:14:50
Original
1050 people have browsed it

php prohibits browsers from using cached pages, php prohibits caching of pages

The example in this article describes how to prevent the browser from using cached pages in PHP. Share it with everyone for your reference. The specific method is as follows:

Page caching is sometimes not needed. We can prevent the browser from caching the page.

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:

Copy code 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:
Copy code The code is as follows:
header("Cache-Control:no-cache,must-revalidate,no-store"); //This After no-store is added, it will be valid under 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.

I hope this article will be helpful to everyone’s PHP programming design.

How to return to the original page when php prohibits the browser from using cached pages

As long as the server-side design is rigorous, there is no point in doing it on the client-side.
The page expiration is the set http header. If you want to modify the header, you have to intercept the http data communication packet. After the modification is completed, it is not easy to restore the http conversation.
And the designer usually sets a certain mark to indicate that the test is over after submission. Even if you can submit again, there will definitely be errors. Of course, it does not rule out that the designer is a stupid person. Condition.

How to prevent the browser from "back" and then "forward" in a PHP page to return to this page and use cache

Add these three lines of code to the page and see if it works:
header("Expires: -1");
header("Cache-Control: no_cache");
header("Pragma: no -cache");

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/907833.htmlTechArticleHow to prohibit browsers from using cached pages in php, php prohibits caching of pages. This article tells an example of php prohibiting browsers from using caches. page method. Share it with everyone for your reference. Specific methods...
Related labels:
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