How PHP avoids repetitive program execution

Source: Internet
Author: User
Keywords Php
If inserting a data into the database succeeds and jumps to the next page and then returns and inserts a piece how to avoid

Reply content:

If inserting a data into the database succeeds and jumps to the next page and then returns and inserts a piece how to avoid

//表单页面
  
   //提交页面session_start();if (!isset($_SESSION['token']) || $_POST['token'] != $_SESSION['token']) {    die('重复提交');}unset($_SESSION['token']);//code..

Add a one-time "voucher" in your post form, the voucher is signed by the logic that generated the form page, cached, and then in the logic to accept the post, check the validity of the credentials, effectively execute the save write to the database, and clean out the credentials;
1. The first request, the credentials are not timed out and valid, passed.
2. Return the request address, the actual post is the same data in the past, but the voucher has been cleared for the first time, will detect the credential invalidation.
3. Multiple simulated (malicious) post requests, credentials are associated, and have time-sensitive and one-time characteristics, and will not carry out saving data.

Try, struck, look at June--!

Add a timestamp voucher that is read after the current time and how many seconds are not repeated in the library.

Set a global flag (True/false), and then use if to determine the flag and then insert it.

Or no return after submission

Each time the form generates a unique and variable token , it generates the corresponding session , and then commits, validates the token. When the database is inserted successfully, clear the session. Tokens fail even if you repeat the click!

  • Related Article

    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.