Prevents repeated submission of forms, refresh protection, and anti-Rewind _ form effects in javascript

Source: Internet
Author: User
In javascript, the solution prevents repeated submission of forms, refresh protection, and server-side backend protection. This is my most recommended method. The advantage is accuracy and maximum compatibility.

Practice: display the form on page a, submit it to page B for processing, and redirect it to Page c to display the result after processing.

1.0 generate a flag ID in the session when you access page a, for example

// Pseudocode
Session ("submitID") = random ()
Then write the value to a hidden input in the form.

// Pseudocode
<% Response. write (" ") %>
1.1 when processing the page B, determine whether the value of submitID2 submitted by the form is consistent with the value of submitID in the session. If the value is inconsistent, redirect it to the error page. If the value is consistent, clear the submitID in the session and process the form.

// Pseudocode
Session ("submitID") = ""
// Then process and submit ......
Redirect to the c page after processing.

1.2 Page c is actually nothing to say, it is a page that displays the processing result.

2. Solve the problem with js on the client
This method is not good, because it will inevitably encounter compatibility issues with different browsers, and it will inevitably be bypassed. The only advantage is that it is simple and does not require much encoding.

2.0 prevent rollback
Add this code at the top of each page

Script window. history. forward (); script
2.1 prevent refresh
It is hard for me to think of any good way to do this. Because there are too many places to block. We had to adopt a very bad method:

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.