PHP restricts user to post comment instance code after 60 seconds

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags code comment create date default ip key name

.
//php tutorial limits user 60 seconds post Comment Instance code
/*
CREATE TABLE ' test '. ' abc ' (
' id ' int (4) NOT NULL auto_increment,
' Times ' Int (4) NOT null default ' 0 ',
' IP ' varchar null default NULL,
Primary key (' ID ')
) engine = MyISAM
*/ if ($_post)
{
  $conn = mysql tutorial _connect (' localhost ', ' root ', ' root ') or Die (' MySQL server 2001 ');
  mysql_select_db (' Test ', $conn);
  $date = time ();
  $IP = $_server[' remote_addr '];//gets the IP address, which is a test so it's not judged
  $wait = "Select Times,ip from ABC where ip= ' $ip ' and ($date-times<60) Order BY id DESC limit 1 ";


$rows = mysql_query ($wait) or Die (Mysql_error ());
if (mysql_num_rows ($rows))
{
Die (' Sit down and take a rest, you move too fast, please release your message in 60 seconds! ');
}
Else
{

$sql = "INSERT INTO ABC (TIMES,IP) VALUES (' $date ', ' $ip ')";
$insert = mysql_db_query (' Test ', $sql, $conn);
if ($insert)
{
Echo ' comment success ';
}
Else
{
Echo ' comment failed ';
}

}
}
?>

<form name= "Form1" method= "post" action= ">
<label for= "TextField" ></label>
<input type= "text" name= "Jzread" id= "TextField" >
<input type= "Submit" name= "button" id= "button" value= "comment" >
</form>

Related Article

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.