PHP records IP to prevent repeated form submission method analysis, ip form_PHP tutorial

WBOY
Release: 2016-07-13 10:11:38
Original
840 people have browsed it

php records IP to prevent repeated form submission method analysis, ip form

This article analyzes the example of how PHP prevents repeated submission of forms by recording IP. Share it with everyone for your reference. The specific analysis is as follows:

This principle is relatively simple. When the user submits for the first time, we record the IP address of the submitting user. In this way, if the user submits the form again within a fixed period of time, he will be prompted to submit again. This approach is usually used for upvoting. Please support this kind of application. It is a very bad choice to prevent repeated submission of data.

Example, the code is as follows:

Copy code The code is as follows:
session_start();
if(empty($_SESSION['ip']))//The first write operation, determine whether the IP address is recorded, so as to know whether to write to the database
{
$_SESSION['ip']=$_SERVER['REMOTE_ADDR'];//The first write will pave the way for subsequent refresh or retreat judgments
mysql_query("INSERT INTO admin(id, name, age) VALUES(123, 'Yao Ming', 25)");//Write to database operation
}
else//There has been an operation after the first write, so it will no longer be written to the database
{
echo 'Please do not submit the form repeatedly or refresh the page';//Write some prompts or other things that have already been written
}
?>

Another way is:

1: Generate a random code on the page, that is, the random code will be different every time you submit it. Verify the random code when submitting!

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

If you want to prevent repeated submission of IP addresses, it is not the best way. We can check whether there are the same records in the database and whether the IPs are the same before processing.

Example, the code is as follows:

Copy code The code is as follows:
$sql ="select * from table name where buy_tel='telephone' and IP='$ip' "; // and $time-buy_date<60
$query = $db->query( $sql );
if( $db->rows( $query ) )
{
echo('<script>alert("You have already submitted, please do not submit again!");</script>');
}
else
{
//Carry out warehousing operation
}

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/928215.htmlTechArticlephp prevents repeated submission of forms by recording IP. Analysis of the method of ip form. This article analyzes the example of php preventing repeated submission of forms by recording IP. Form repeated submission method. Share it with everyone for your reference. Specific points...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!