PHP prevents browsers from using cached pages _php tips

Source: Internet
Author: User

The example in this article describes how PHP prevents browsers from using cached pages. Share to everyone for your reference. The specific methods are as follows:

The slow existence of pages is sometimes unwanted, and we can prevent browsers from caching pages.

In PHP, you can easily use the following statement to achieve the prohibition of page caching, but more difficult to remember the special collation, convenient for everyone to use.
The PHP code is as follows:

Copy Code code as follows:
Set the expiration time for this page (expressed in GMT), as long as it is a date that is already past.
Header ("Expires:mon, June June 1970 05:00:00 GMT");
Set the last update date for this page (in Greenwich Mean Time) for the same day, you can force the browser to get the latest information
Header ("last-modified:"). Gmdate ("D, D M Y h:i:s"). " GMT ");

Tells the client browser not to use caching, HTTP 1.1 protocol
Header ("Cache-control:no-cache, must-revalidate");

Tells the client that the browser does not use caching, which is compatible with the HTTP 1.0 protocol
Header ("Pragma:no-cache");

This is useful for some pages, such as a single message and a product under an order, and empty the cart's corresponding product data.
Certainly do not want users to the last page, have already generated orders, and then click the Return button browser back to the previous page.
Then in the Order Address page add:
Copy Code code as follows:
Header ("Cache-control:no-cache,must-revalidate,no-store"); After this no-store is added, Firefox works.
Header ("Pragma:no-cache");
Header ("Expires:-1");

This page is not cached, and there is a judge shopping cart merchandise to jump to empty shopping cart page, then the user clicks on the browser back, back, also directly to the shopping cart page.

I hope this article will help you with your PHP program design.

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