PHP prohibit page Cache code Introduction _php Tutorial

Source: Internet
Author: User
The code that disables page caching in PHP is fairly straightforward, as long as you use the PHP header () browser to send a cache-control:no-cache or set the page cache expiration time for you before today.

Some friends say the simplest way to disable page caching

The code is as follows Copy Code
Header ("Cache-control:no-cache, must-revalidate");


Here I'll give you some PHP code to use:

The code is as follows Copy Code
Header ("Expires:mon, Jul 1997 05:00:00 GMT");
Header ("Cache-control:no-cache, must-revalidate");
Header ("Pragma:no-cache");

Let's take a look at the HTTP response message, in fact we can use the Telnet command to view, below I give the point HTTP response content: http/1.1 OK
server:microsoft-iis/6.0
Date:thu, Oct 11:20:53 GMT
Content-type:text/html
Set-cookie:name=value; path=/
Cache-control:private

Let's take a look at the details below.

The code is as follows Copy Code

Set the expiration time for this page (in GMT), as long as the date has passed.
Header ("Expires:mon, Jul 1970 05:00:00 GMT");

Set the last update date for this page (expressed in GMT) to force the browser to get the latest information for the current day
Header ("last-modified:".) Gmdate ("D, D M Y h:i:s"). "GMT");

Tells 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, compatible with the HTTP 1.0 protocol
Header ("Pragma:no-cache");


?>

Just put the above code at the very beginning of your PHP page, or the header function might go wrong. So you have to put it at the beginning of the document.

http://www.bkjia.com/PHPjc/631282.html www.bkjia.com true http://www.bkjia.com/PHPjc/631282.html techarticle The code that prohibits page caching in PHP is fairly straightforward, as long as you use the PHP header () browser to send a cache-control:no-cache or set the page cache expiration time for you before today ...

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