Php disables the browser from caching pages, and php disables caching pages

Source: Internet
Author: User

Php disables the browser from caching pages, and php disables caching pages

This article describes how php disables browsers from caching pages. Share it with you for your reference. The specific method is as follows:

Page caching is not required sometimes. We can disable 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 it for your convenience.
The php code is as follows:

Copy codeThe Code is as follows: <? Php
// Set the expiration time of this page (expressed by 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 update date (expressed by Greenwich Mean Time) on this page to the current day. You can 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 the cache, HTTP 1.1 protocol
Header ("Cache-Control: no-cache, must-revalidate ");
 
// Tells the client browser not to use the cache and is compatible with the HTTP 1.0 Protocol
Header ("Pragma: no-cache ");
?>
This is useful for some pages, such as single information and items under the order, and clearing the corresponding item data of the shopping cart.
If you do not want the user to go to the last page, the Order has been generated, and then click the return button of the browser to return to the previous page.
On the order address page, add:
Copy codeThe Code is as follows: header ("Cache-Control: no-cache, must-revalidate, no-store"); // after this no-store is added, it is valid in Firefox.
Header ("Pragma: no-cache ");
Header ("Expires:-1 ");
This page is no longer cached, and a page will jump to the empty shopping cart if it is determined that the shopping cart item is empty. Then, the user clicks the browser and returns to the shopping cart page.

I hope this article will help you with PHP programming.


How can I return the original page when php disables the browser from using the cache page?

As long as the server design is rigorous, it doesn't make sense for you to do anything on the client.
Page expiration is the configured http header. to modify the header, You have to intercept the http data communication packet and resume the http conversation after modification. this is not difficult.
In addition, the designers usually set a mark after the submission to indicate that the test is over. Even if you can submit the test again, the error will certainly occur. Of course, it is not ruled out that the designer is very stupid.

On the PHP page, how does one disable the browser from "backward" and then "Forward" and return to this page to use the cache?

The following code cannot be added to the page:
Header ("Expires:-1 ");
Header ("Cache-Control: no_cache ");
Header ("Pragma: no-cache ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.