Home  >  Article  >  Backend Development  >  PHP code to disable page caching_PHP tutorial

PHP code to disable page caching_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:24:31635browse

Core code:

Copy code The code is as follows:

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must -revalidate");
header("Pramga: no-cache");

This is useful for some pages, such as: verification code, because each time it is generated The verification code must be different, otherwise the verification code will have no meaning, so you can use the above statement to disable caching.
Another example: "Change a picture of a beautiful woman every time you post". Page caching must be disabled, otherwise the same picture in the cache will be returned.
I recently saw the "League Chronicles" on Baidu Alliance - "How to make netizens fall in love with your website" (mainly discussing how to improve user experience) and reminded me of this:
Take the forum as an example, when a user logs in The last page displayed is the page after login, such as "Management", "Modify Information", etc. When the user exits the forum and returns to the previous page,
there are still "Management", "Modify Information", etc. (because the returned Cache page), although the cookies have been cleared at this time, "Manage", "Modify Information", etc. have no effect,
but the user still thinks that this is a valid page, and thus thinks that others can also "Manage", "Modify" Information", etc., thinking that the website is unsafe (even though it is actually safe). At this time, it is very useful to add the above code to the page that requires cookie verification. At least it can eliminate the negative impact on the user's psychology.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324329.htmlTechArticleCore code: Copy the code as follows: header("Expires: Mon, 26 Jul 1997 05:00:00 GMT "); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Cache-Control: no-cache...
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