thinkphp methods to prevent form recurrence _php tips

Source: Internet
Author: User
There is one situation, however, that cannot be prevented:

After the user submits the form, click the browser Back button to return to the form page, this time the browser will be directly from the cache to remove the page, so token verification must be pass.

There are a number of ways to circumvent this problem, such as replacing the current history with the Location.replace () method, but this is still flawed. In extreme cases, if the user switches between pages several times, then a few more times the back button is likely to return to the previous form page.

The workaround is to set the Cache-control:no-cache in the HTTP header, No-store. However, I tried to add <meta http-equiv= "Cache-control" content= "No-cache, No-store" > or output Header ("in action") either in the page head. Cache-control:no-cache, No-store ") are invalid.

Looking for a long time, found the problem in the thinkphp template rendering mechanism, open thinkphp/lib/think/core/view.class.php to see line 173th

header("Cache-control: private");  //支持页面回跳

The original TP in order to support page bounce, forcing the output of each template before sending a cache-control:private head, it is really helpful to the busy.

Comment out this line, delete the TP core cache, and try again to discover that the HTTP response header has successfully changed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.