Home >Backend Development >PHP Tutorial >PHP prevents refresh and repeated submission of example code
Prevent direct access to the PHP page, only quote it! In this way, you cannot directly access the B page. You can also add COOKIE to A and delete the COOKIE after B determines the COOKIE. Prevent module refresh So I considered adding a parameter to prevent this kind of situation from happening. COOKIE and SESSION are available, but COOKIE is client-side. If someone disables COOKIE, they can still maliciously refresh the number of clicks. It is better to use SESSION. The MD5 value of IP+URL parameters is used as the SESSION name. I think it is difficult for everyone to forge it. Implementation principle: Set max_reloadtime =100; //Set the maximum page refresh interval The first time the user opens the page, the current time is recorded and saved in session_start The second time the user opens the page (to determine whether session_start exists) subtracts the current time from session_start to get the difference time_passed When time_passed Example:
Example 2, PHP prevents duplicate submission. First, you can define a session variable to save the submission sequence number of a form. This is defined as "$userLastAction". Then, add a hidden variable to the form and set the value to $userLastAction+1: > Finally, determine whether the form has been submitted before processing the submission:
Submit page:
Submitted page:
|