How to prevent page caching in thinkphp 3.2

不言
Release: 2023-04-03 19:46:01
Original
2634 people have browsed it

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)
Copy after login

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)
Copy after login

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)
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!