When using the Baidu tool for a small test, we were prompted that we had to set the static content cache time. I had no server permission to operate on myself and had to start from other aspects, after I searched for php, I found that I could use the header function to cache pages in the browser... when using the Baidu tool for a small test, we were prompted that we had to set the static content cache time. I had no server permission to operate on myself and had to start from other aspects, after I searched for php, I found that I could use the header function to cache pages in the browser.
Set the static content cache time. the code is as follows:
$interval = 60 * 60 * 6; // 6 hours header ("Last-Modified: " . gmdate ('r', $max)); header ("Expires: " . gmdate ("r", ($max + $interval))); header ("Cache-Control: max-age=$interval");
We add the above code to the beginning of the PHP file. The following describes the four lines of code. the code is as follows:
$ Interval = 60*60*6; // 6 hours header ("Last-Modified :". gmdate ('R', $ max); header ("Expires :". gmdate ("r", ($ max + $ interval); header ("Cache-Control: max-age = $ interval "); $ aid = intval (isset ($ _ POST ['aid '])? $ _ POST ['aid ']: 0); if (! $ Aid) // open source code phprm.com {echo 'undefined ads';} else if ($ aid = 1) {echo 'load ad content ';}
The first line: $ interval tells you that it has been set for six hours. you can customize it here.
Row 2: send a Last-Modified request to the client browser, which calls the corresponding date based on the gmdate parameter r.
Row 3: the expiration time of Expires is set.
Row 4: Set the max-age = $ interval date of Cache-Control.
The test result is excellent.
Link to this article:
Add to favorites ^ please keep the tutorial address.