PHP uses header to set browser cache

Source: Internet
Author: User
Tags browser cache
The function of the header () is to send an original HTTP header [HTTP header] to the client.
The header is a string sent by the server to the browser before the HTML data is transmitted to the HTTP, in the header
There is an empty line separating the HTML file. Let me share with you a PHP technology that uses the header to set the browser cache.

<?php     //define a reasonable cache time. The reasonable value of the page itself, the number of visitors and the page update frequency, here is 3,600 seconds (1 hours).     $cache _time = *;    $modified _time = @$_server[' http_if_modified_since ');    if (Strtotime ($modified _time) + $cache _time > Time ()) {         header ("http/1.1 304");         Exit;     }     Sends the last-modified header, setting the last updated date for the document.     header ("last-modified:". Gmdate ("D, D M Y h:i:s", Time ()). " GMT ");          Send the Expires header, set the current cached document expiration time, GMT format, we are using the gmt+8 time zone    header ("Expires:". Gmdate ("D, D M Y h:i:s", Times () + $cache _time) ." GMT ");          Send Cache_control header, set xx seconds after the document obsolete, can replace expires, if at the same time, max-age priority.     header ("cache-control:max-age= $cache _time");     echo time ();     ? >

about using the header () function. And you have a lot of knowledge, the next small series will continue to share with you about the usage of the PHP header function and its considerations, and so on.

Related Article

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.