PHP TO SOLVE AND AVOID THE FORM FORM TO REPEAT THE SUBMISSION METHOD

0 k thích
đã hỏi ngày 14 tháng 12 năm 2017 bởi WilburTazewe (180 điểm)
When submitting the form, you may encounter network speed and other causes the page to suddenly load slow, the user repeatedly click on the submit button, will generate multiple data in the database, resulting in uncontrollable situation.

double content checkerSuch as the following circumstances will lead to duplicate forms submitted:

Click the submit button twice.

Click the Refresh button.

Use the browser back button to repeat the previous operation, resulting in repeated submission of the form.

duplicate copy checker the form using the browser history.

The browser repeats the HTTP request.

The page was maliciously refreshed.

Here are a few ways to solve:

One: use js set button click into gray

$ (document) .ready (function ()

$ (input: submit) .click ()

setTimeout (function () obj.disabled = true;, 100)

;

);

Two: the use of session

When loading the submitted page, generate a random number,

$ code = mt_rand (0,1000000);

Stored in the hidden input box of the form:

\u0026 lt; input type = 'hidden' name = 'code' value = '\u0026 ldquo; \u0026 gt;

The PHP code on the receiving page is as follows:

\u0026 lt;? php

session_start ();

if (isset ($ _ POST ['code']))

if ($ _ POST ['code'] == $ _ SESSION ['code'])

// Submit the form again

else

$ _SESSION ['code'] = $ _ POST ['code']; // store the code



? \u0026 gt;

Three: the use of cookies

The principle and the session almost, but the cookie once the user browser to disable cookies, this function is invalid

if (isset ($ _ POST ['submit']))

setcookie ('tempcookie', '', time () + 30);

header ('Location:'. $ _ SERVER [PHP_SELF]); exit ();



if (isset ($ _ COOKIE ['tempcookie']))

setcookie ('tempcookie', '', 0); echo 'You have already submitted the form';



Four: use the header function to jump

Once the user clicks the submit button, the data is processed and jumps to another page

if (isset ($ _ POST ['submit']))

header ('location: success.php'); / / processing data, turn to other pages



Five: use the database to add constraints

Directly in the database to add a unique constraint or create a unique index, once the user repeatedly found, and directly throw a warning or prompt,

Or only deal with the first submitted data, which is the most direct and effective way to require pre-database design and architecture to be considered comprehensive

Câu trả lời của bạn

Tên hiển thị của bạn (tùy chọn):
Bảo mật: Địa chỉ email của bạn chỉ được dùng để gửi thông báo.
  1. BlancaMancus

    13780 points

  2. TristanBusch

    13020 points

  3. Kelvin582250

    11000 points

  4. BrianneAinsw

    10440 points

Monthly rewards
1. Place: USD 20
2. Place: USD 10
3. Place: USD 5

901,350 câu hỏi

168,571 trả lời

1,653 bình luận

869,504 thành viên

Những câu hỏi liên quan

0 k thích
0 trả lời
0 k thích
0 trả lời
0 k thích
0 trả lời
0 k thích
0 trả lời
đã hỏi ngày 12 tháng 12 năm 2017 bởi KristeenCald (180 điểm)
0 k thích
0 trả lời
đã hỏi ngày 12 tháng 12 năm 2017 bởi KristeenCald (180 điểm)
...