In web development, preventing repeated submission is a practical and common problem. besides, you can directly query the database to see if users submit the same data for filtering, we can also prevent this kind of thing from being discovered when the user submits data. next I will introduce sessi-based... in web development, preventing repeated submission is a practical and common problem. besides, you can directly query the database to see if users submit the same data for filtering, we can also prevent such cases from being discovered when users submit data. next we will introduce some implementation methods based on session-based and cookies-based anti-repeated submission.
Prevents refresh or resubmit
Therefore, we should consider adding a parameter to prevent such cases. cookies and sessions are available. However, cookies are client-side. if cookies are disabled, we can refresh the clicks maliciously. Use the MD5 value of the IP + URL parameter as the SESSION name.
Implementation principle setting max_reloadtime = 100; // sets the maximum interval between page refreshes.
When the user opens the page for the first time, the current time of the record is saved in session_start.
The second time the user opens the page (determines whether session_start exists), the difference time_passed is obtained by subtracting the current time from session_start.
When time_passed <max_reloadtime indicates that the user refresh the warning frequently within the specified time and then exits directly
$ AllowTime) {$ refresh = true; $ _ SESSION [$ allowT] = time ();} else {$ refresh = false;}?>
Prevent repeated submission of forms
'; Print_r ($ _ POST); print 'Please try again'; print'
'; $ _ SESSION ['num'] = 500;} else {print'
'; print_r($_POST); echo "However you have submitted"; print '
';}} Else {session_start () or die ("session is not started"); $ _ SESSION ['num'] = 400;?>
For example, a smarty-based demo version
Assign ('code', $ code);?>
10. //// prevent repeated submission of forms
In the tpl Template
1.
"> // The code on the receiving page is as follows: session_start (); if (isset ($ _ POST ['originator']). {if ($ _ POST ['originator'] = $ _ SESSION ['code']) {// statement for processing the form, omitted} else {echo '. please do not refresh this page or submit the form again! ';}}?>
Permanent link:
Reprint at will! Include the article address.