Php records IP addresses to prevent repeated form submission methods for analysis. ip form _ PHP Tutorial

Source: Internet
Author: User
Php records IP addresses to prevent repeated form submission methods for analysis and ip address forms. Php record the IP address to prevent repeated form submission. This article analyzes the ip address record in php to prevent repeated form submission. Share it with you for your reference. Php records IP addresses to prevent repeated submission of forms for analysis.

In this example, php records IP addresses to prevent repeated submission of forms. Share it with you for your reference. The specific analysis is as follows:

This principle is relatively simple. when the user submits the request for the first time, we record the IP address of the user. if the user submits the form again within a fixed period of time, the system will prompt repeated submission, this method is usually used in the top step to support such applications. it is a very bad choice to prevent repeated data submission.

The code is as follows:

The code is as follows:

<? Php
Session_start ();
If (empty ($ _ SESSION ['IP']) // The first write operation to determine whether the ip address is recorded and whether to write data to the database
{
$ _ SESSION ['IP'] = $ _ SERVER ['remote _ ADDR ']; // writes data for the first time, paving the way for refresh or rollback judgment.
Mysql_query ("insert into admin (id, name, age) VALUES (123, 'Yao Ming ', 25)"); // write to the database
}
Else // the operation after the first write will no longer be written to the database
{
Echo 'do not submit the form repeatedly or refresh the page'; // write some written prompts or other things
}
?>


There are also ways to do this:

1: generate a random code on the page, that is, the random code is different each time you submit it. verify the random code when you submit it!

2: when submitting, verify that if the data exists, it will not be submitted.

If you want to prevent repeated submission of inbound IP addresses, it is not the best solution. we can query the database to see if there are the same records and whether the IP addresses want to be processed again.

The code is as follows:

The code is as follows:

$ SQL = "select * from table name where buy_tel = 'telephony 'and IP =' $ IP'"; // and $ time-buy_date <60
$ Query = $ db-> query ($ SQL );
If ($ db-> rows ($ query ))
{
Echo ('script alert ("you have submitted it. please do not submit it again! "); Script ');
}
Else
{
// Perform the warehouse receiving operation
}

I hope this article will help you with PHP programming.

In this example, php records IP addresses to prevent repeated submission of forms. Share it with you for your reference. Details...

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.