PHP to prevent form repeat submission method analysis by recording IP, IP form _php Tutorial

Source: Internet
Author: User

PHP prevents forms from repeating the method analysis by recording IP, IP form


In this paper, we analyze how PHP can prevent form recurrence by recording IP. Share to everyone for your reference. The specific analysis is as follows:

The simple comparison of this principle is that when the user first commits, we record the IP address of the submitting user, so that if the user submits the form again within a fixed time, it will prompt to repeat the submission, which is often used in the top, support the application, in the prevention of repeated data submission is a very bad choice.

example, the code is as follows:
Copy the Code code as follows: <?php
Session_Start ();
if (Empty ($_session[' IP]))//First write operation, determine whether the IP address is logged, to know whether to write to the database
{
$_session[' IP ']=$_server[' remote_addr '];//first write, for the back of the decision to refresh or back to make a cushion
mysql_query ("INSERT into admin (ID, name, age) VALUES (123, ' Yao ', 25)");//write database operations
}
else//already has the first write operation and no longer writes to the database
{
Echo ' Please do not submit the form again or refresh the page ';//write some hints or other things that have been written
}
?>
There are also ways to:

1: Generate random code on the page, that is, each time the random code is not the same, at the time of submission to verify the random code!

2: At the time of submission, verify that if the data exists, it is not committed.

If you want to prevent duplicate submission of inbound IP is not the best way, we can query in the database is not the same record and IP is not to be processed again.

example, the code is as follows:
Copy the code as follows: $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 (');
}
Else
{
For inbound operations
}

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/928215.html www.bkjia.com true http://www.bkjia.com/PHPjc/928215.html techarticle PHP by recording IP to prevent the form of repeated submission method analysis, IP form this article analyzes PHP through the record IP to prevent form duplicate submission method. Share to everyone for your reference. Specific points ...

  • 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.