Php form repeated submission implementation method, php form repeated submission _ PHP Tutorial

Source: Internet
Author: User
Php forms can be submitted repeatedly. To solve the php form repeated submission implementation method, repeated submission of php forms is a common problem during development. apart from using js to prevent repeated submission of forms, at the same time, it solves the php form repeated submission implementation method, and php form repeated submission

Repeated submission is a common problem during development. in addition to using js to prevent repeated submission of forms, php can also be used to prevent repeated submission.

<? Php/** php: how to prevent repeated forms */session_start (); if (empty ($ _ SESSION ['IP']) {// The first write operation, determine whether an ip address is recorded to know whether to write data to the database $ _ SESSION ['IP'] = $ _ SERVER ['remote _ ADDR ']; // The first write operation, pave the way for refresh or backend judgment //........... // database write operation} else {// the operation after the first write is performed, and the echo will not be written into the database. 'Please do not refresh or rewind '; // write some written prompts or other things}?>

Principle
The token of the session range variable is prevented.
1. enable session:
Session_start ();
2. if a form is submitted

 if (isset($token))

The token is included in the form of hidden.


3. if the form is submitted repeatedly

If ($ _ SESSION ["token"]! = $ Token) {// do not allow repeated submission. process it here // header ("location :". $ _ SERVER ['php _ SELF ']);} else {// normal form submission, which is processed here // echo "submitted ";}

4. set the token value
$ Token = mt_rand );
2 $ _ SESSION ['token'] = $ token;

The above is about how to solve the php form repeated submission implementation method, hope to help you learn.

Repeated commit is a common problem during development. besides using js to prevent repeated submission of forms...

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.