Home >Backend Development >PHP Tutorial >thinkpad s230u twist ThinkPHP method to prevent repeated submission of forms
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
"Cache-control: private" ); //Support page bounce
|