thinkpad s230u twist ThinkPHP method to prevent repeated submission of forms

WBOY
Release: 2016-07-29 08:46:29
Original
1374 people have browsed it

However, there is one situation that cannot be prevented:

After the user submits the form, click the browser's back button to return to the form page. At this time, the browser will directly retrieve the page from the cache, so the token verification must fail.

There are many ways to circumvent this problem on the Internet, such as using the location.replace() method to replace the current history record, but this still has flaws. In extreme cases, if the user switches between pages multiple times, clicking the back button several times may return to the previous form page.

The solution is to set Cache-Control: no-cache, no-store in the http header. However, I tried adding in the page head. After searching for a long time, I found that the problem lies in ThinkPHP's template rendering mechanism. Open ThinkPHP /Lib/Think/Core/View.class.php Look at line 173 ThinkPHP 防止表单重复提交的方法

header(
"Cache-control: private"); //Support page bounce
It turns out that in order to support page bounce, TP is forced to send a Cache-control: private header before each template is output, which is really a disservice. Comment out this line, delete the TP core cache, try again, and find that the HTTP response header has been successfully changed

The above introduces the thinkpad s230u twist ThinkPHP method to prevent repeated submission of forms, including the content of thinkpad s230u twist. I hope it will be helpful to friends who are interested in PHP tutorials.  ThinkPHP 防止表单重复提交的方法

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!