The example of this paper is to analyze the way that PHP prevents form recurrence by recording IP. Share to everyone for your reference. The specific analysis is as follows:
This principle is relatively simple is the first time the user submitted when we record the user's IP address, that way, if the user submits the form again within a fixed time, it prompts for a repeat submission, which is often used to support the application at the top, which is a very bad option to prevent duplication of data submissions.
example, the code is as follows:
The code is as follows |
Copy Code |
<?php Session_Start (); if (Empty ($_session[' IP '))//first write to determine whether the IP address is logged, to know whether to write to the database { $_session[' IP ']=$_server[' remote_addr '];//first written to pave the back for a refreshing or receding judgment mysql_query ("INSERT into admin (ID, name, age) VALUES (123, ' Yao Ming ', 25)"); Write to database operations } Else//has already had the first write operation and is no longer writing to the database { Echo ' Please do not repeat the form or refresh the page '; write some hints or other things that have been written } ?> |
There is another way:
1: In the page generated random code, that is, each submit random code is not the same, in the submission of the time to verify the random code!
2: At the time of submission, verify that if the data exists, it will not be submitted.
If you want to prevent repeated submissions to the incoming IP is not the best way, we can query in the database is not the same record and IP is not want to work with again.
example, the code is as follows:
The code is as follows |
Copy Code |
$sql = "SELECT * from table name where buy_tel= ' phone ' and ip= ' $ip";/and $time-buy_date<60 $query = $db->query ($sql); if ($db->rows ($query)) { Echo (' <script>alert you have already submitted, do not repeat! ");</script> '); } Else { To make a storage operation } |
I hope this article will help you with your PHP program design.