Home >Backend Development >PHP Tutorial >PHP sets the cache of dynamic web pages in the browser, static web pages and dynamic web pages, web page dynamic pictures, web page dynamic picture production

PHP sets the cache of dynamic web pages in the browser, static web pages and dynamic web pages, web page dynamic pictures, web page dynamic picture production

WBOY
WBOYOriginal
2016-07-29 08:52:431608browse

Many people may not know that dynamic web pages can also be cached in browsers. The following uses a PHP script as an example to explain how to set up dynamic web pages to be cached in the browser

//Set the web page expiration time to 1 hour

$duetime = 3600*24*30取 // Get the browser to transmit to the server

Last-Modify

Head $ Modify_time = $ _Server ['http_if_modify_since'];

// When the browser sets time to set time When accessing the web page again within a certain period of time, the status code of HTTP

304

will be sent, thus saving the amount of data to be transmitted. if(strtotime($modify_time) + $duetime > time())

{

header('HTTP/1.1 304');

exit(1);

}

header('Connection: keep-alive');

//Set up web page

Last-Modified

headerheader('Last-Modified: '.gmdate(' D, d M Y H:i:s').' GMT');

//Set the webpage expiration time

header('Expires: '.gmdate('D, d M Y H:i:s', time()+$duetime).' GMT');

//The execution cache time is long, somewhat similar to

Expires,

allows us to more comprehensively control the web page expiration time, because the browser time may be different from The server time is not coordinated, and the Cache-Control header can be limited. header('Cache-Control: max-age='.$duetime);

//Output content

...

?>

Original text: http://woqilin.blogspot.com/2014/05/php.html

The above introduces how to set up the browser cache of dynamic web pages in PHP, including dynamic web pages and browser content. I hope it will be helpful to friends who are interested in PHP tutorials.

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