Home >Backend Development >PHP Tutorial >How to prevent page caching in thinkphp 3.2

How to prevent page caching in thinkphp 3.2

不言
不言Original
2018-08-17 17:27:332684browse

The content of this article is about how to control the page without caching in thinkphp 3.2. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

When developing WAP websites recently, the most annoying thing is the back button, which can cause some trouble. However, there is always a way to solve the problem.

For some pages, clicking the back button will load the cache. This is not what you want, so you hope to be able to control the page not to be cached. Every request needs to get the latest data from the server.

The solution is to control the HTTP Cache-control header

![image](http://upload-images.jianshu.io/upload_images/2376873-9430d2fe3abc1f43?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

As you can see, the default Cache-control of Thinkphp 3.2 is private

That’s because the default in the configuration file Set to private

![image](http://upload-images.jianshu.io/upload_images/2376873-7f8fa48005716d81?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

When the page is rendered, set the value in this configuration to the Cache-control header

![image](http://upload-images.jianshu.io/upload_images/2376873-88a2fed7ee3bbac7?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

Based on the above information, at first I just thought Two solutions:

1. Modify the value in the configuration => Unrealistic, modified globally

2. Rewrite the source code => TP cannot be so stupid

The final solution is: set `C('HTTP_CACHE_CONTROL',"no-store");`

![image](http://upload-images.jianshu.io/upload_images/2376873-7e4120004aaedadf?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

Related recommendations:

How to implement page caching

How to prevent the page from caching data_html/css_WEB-ITnose

The above is the detailed content of How to prevent page caching in thinkphp 3.2. For more information, please follow other related articles on the PHP Chinese website!

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